单个节点的后插操作.txt
来自「数据结构用C实现」· 文本 代码 · 共 43 行
TXT
43 行
///////////////////////////////////////////////
// 作者:03031A班 李戬 //
// //
// 2003年 xx月 xx日 晚 //
///////////////////////////////////////////////
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
#include<malloc.h>
typedef int datatype;
typedef struct node
{
datatype data;
struct node *next;
}linklist;
void main()
{
linklist *head,*s,*r;
int i,j,k,w;
cout<<"please enter a total number"<<endl;
cin>>i;
head=NULL;
for(j=1;j<=i;j++)
{
cout<<"please enter a number"<<endl;
cin>>k;
s=(linklist *)malloc(sizeof(linklist));
s->data=k;
if(head==NULL) head=s;
else
head->next=s;
head=s;
cout<<endl<<s->data<<endl;
}
r=(linklist *)malloc(sizeof(linklist));
cout<<"请输入要插入的数值:"<<endl;
cin>>w;
r->data=w;
r->next=s->next;
s->next=r;
cout<<endl<<s->next->data<<endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?