#include <bits/stdc++.h>
using namespace std;
typedef struct node
{
int data;
struct node *next;
}no;
int main()
{
no *head,*tail,*p,*q;
head=new no;
head->next=NULL;
tail=head;
int n;
printf("一共要输入的数:");
cin>>n;
int k;
cin>>k;
for(int i=0;i<n;i++)
{
p=new no;
p->data=k;
p->next=NULL;
tail->next=p;//因为tail=head,所以tail没有数值,tail->next才有数值
tail=p;
cin>>k;
}
printf("输入要插入的数:");
int m;
cin>>m;
q=new no;//生成一个结点来存放这个数
q->data=m;
q->next=NULL;
printf("要插在哪个数和哪个数之间:");
int a,b;
cin>>a>>b;
p=head;
while(p->data!=m&&p->next!=NULL)
{
p=p->next;
if(p->data==a&&p->next->data=
C语言实现单链表指定结点的插入
最新推荐文章于 2024-11-12 22:21:08 发布