#include<iostream>
#include<cstdlib>
using namespace std;
//创建一个结构体,表示链表的节点类型
struct node{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*q,*t;
int n,a;
cin>>n;
head=NULL;//将其头指针设置为空
for(int i=1;i<=n;i++){//循环读入n个数,
cin>>a;
//动态申请空间,
p=(struct node*)malloc(sizeof(struct node));
p->data=a;//存放数据
p->next=NULL;//设置这个节点的后一个节点为空
if(head==NULL)//对节点进行判断,是否为第一个创建的节点
head=p;
else q->next=p;// 将上一个节点的后继指针指向这个节点
q=p;//指针q指向这个节点
}
//在链表中对数据进行插入
t=head;
cin>>a;
while(t!=NULL){
if(t->next->data>a){//对t节点的下一个节点的data数据
在一组从小到大排序的数据中插入一个数,使其仍然这样排列
最新推荐文章于 2023-09-17 17:08:02 发布