#include<iostream>
#include<cstdio>
using namespace std;
struct node
{
int num;
node *next;
};
int main()
{
node *head,*p,*q,*r;
int x,n,i;
cin>>n;
head=new node;
cin>>head->num;
head->next=NULL;
q=head;
for(i=2;i<=n;i++)
{
p=new node;
p->next=NULL;
cin>>p->num;
q->next=p;
q=p;
}
p=head;
cin>>x;
while(p!=NULL)
{
if(p->num>=x)
break;
q=p;
p=p->next;
}
r=new node;
r->num=x;
r->next=NULL;
if(p==head)
r->next=head;
else if(p==NULL)
q->next=r;
else
{
q->next=r;
r->next=p;
}
p=head;
while(p->next!=NULL)
{
cout<<p->num<<" ";
p=p->next;
}
cout<<p->num;
return 0;
}
插入排序的单链表实现
最新推荐文章于 2022-04-29 10:19:00 发布