首页 > 编程语言 >Inserting a node at beginning,全局变量头指针【1月16日学习笔记】

Inserting a node at beginning,全局变量头指针【1月16日学习笔记】

时间:2024-01-17 09:34:52浏览次数:23  
标签:Inserting node temp 16 next beginning 节点 指针

点击查看代码
//inserting a node at beginning,全局变量头指针
#include<iostream>
using namespace std;
 
struct node {
	int data;
	node* next;
};
node* A;
 
void insert(int x) {
	node* temp = new node;//创建新节点
	temp->data = x;
	temp->next = A;//新节点尾巴指向1节点(无则NULL)
	A = temp;//头指针指向新节点
}
 
void print() {
	node* run = A;
	while (run!= NULL) {
		cout << run->data << " ";
		run = run->next;
	} cout << endl;
}
 
int main() {
	int x;
	while (cin >> x) {
		insert(x);
		print();
	}
 
}

标签:Inserting,node,temp,16,next,beginning,节点,指针
From: https://www.cnblogs.com/whvivy/p/17969074

相关文章

  • Inserting a node at beginning,局部变量头指针版本1【1月16日学习笔记】
    点击查看代码//insertinganodeatbeginning,局部变量头指针版本1#include<iostream>usingnamespacestd;structnode{ intdata; node*next;};node*insert(intx,node*A){ node*temp=newnode;//创建新节点 temp->data=x; temp->next=A;//新节......
  • Inserting a node at beginning,局部变量头指针版本2【1月16日学习笔记】
    点击查看代码//insertinganodeatbeginning,局部变量头指针版本2#include<iostream>usingnamespacestd;structnode{ intdata; node*next;};voidinsert(intx,node**A){ node*temp=newnode;//创建新节点 temp->data=x; temp->next=*A;//新......
  • 遍历链表,将节点接到末端 【1月16日学习笔记】
    点击查看代码//遍历链表,将节点接到末端#include<iostream>usingnamespacestd;structnode{ intdata;//数据 node*next;//尾巴};//定义节点结构体node*A;//头指针固定,globalvariabl......
  • STM32CubeMX教程16 DAC - 输出3.3V内任意电压
    1、准备材料开发板(正点原子stm32f407探索者开发板V2.4)STM32CubeMX软件(Version6.10.0)keilµVision5IDE(MDK-Arm)ST-LINK/V2驱动野火DAP仿真器XCOMV2.6串口助手2、实验目标使用STM32CubeMX软件配置STM32F407开发板的DACOUT1实现输出0-3.3V任意模拟电压,然后用ADC1_IN5单通......
  • 20230116python基本语法day1
    20230116python基本语法day1代码看一行写一行。菜鸟教程python3成为自己尊重自己欣赏的自己。注意点:python中,#TODO待处理,显示为黄色,这边的问题要在最后解决掉,这很重要。在java中可能是//TODO    解释器的作用是运行文件,给代码解释文件。......
  • 已知IP地址是192.168.5.121,子网掩码是255.255.255.248,求网络地址和主机地址
    方法1首先,将Ip地址转换为二进制:192.168.5.121转换为二进制:11000000.10101000.00000101.01111001然后将子网掩码转换成二进制:255.255.255.248转换为二进制:11111111.11111111.11111111.11111000网络地址=IP地址&子网掩码192.168.5.121&255.255.255.248=192.168.5.12......
  • 英文闲话 2024-01-16
    Iwokeupat6on1-13,thedayofecfinal.IcheckedmyphoneandsurprisinglyfoundthatLolasentmeaemail.Afterannalyzingwhatshetalkedaboutcarefully,IrepliedherwithwhatIthought.InadditionIpraisedWeimingLakeandshowedmyappreciatio......
  • 吴师兄学算法day07 双指针 16. 最接近的三数之和
    题目:16. 最接近的三数之和易错点:比较的时候,要减去target在算结果我的代码:classSolution:defthreeSumClosest(self,nums:List[int],target:int)->int:nums=sorted(nums)max_res=float('inf')min_res=float('-inf')......
  • 2024.1.16做题纪要
    硬币多少有些人类智慧了。。。。。题解写的还行。具体就是每次把当前这一位代表的质数\(i\)向后每隔\(i\)个数除上\(i\)。这一位肯定是一个质数,因为若是合数则前面一定会被除上质数。Kaiserredux#include<bits/stdc++.h>longlongnum[1100000];longlonganswe......
  • 2024-1-16
    0这里是我的博客平台。接下来的博客时间将以学习编程为主题,多多关照。1学习编程的目标——学会编程,实在的插足新领域自夸。#include<stdio.h>intmain(void){charc;do{c=getchar();}while(c!='');printf("\a");printf("helloC\n");p......