1.c
来自「C语言成绩管理系统」· C语言 代码 · 共 57 行
C
57 行
#include "stdio.h"
#define NULL 0
struct node
{ int data;
struct node *next;
};
struct node *creat();
struct node *insert(struct node *head,int value)
{
struct node *new ,*p,*q;
new=(struct node *)malloc(sizeof(struct node));
new ->data=value;
p=head;
if(head==NULL)
{ head=new;
new->next=NULL;
}
else
{ while ((p->next!=NULL)&&(p->data<value))
{ q=p;p=p->next;}
if(p->data>=value)
{ if(head==p)
{ new->next=head;
head=new;
}
else
{ q->next=new;
new->next=p;
}
}
else
{ p->next=new;
new->next=NULL;
}
}
return(head);
}
void main()
{
struct node *q;
int value;
q=creat();
printf("请输入要插入的整数:");
scanf("%d",&value);
q=insert(q,value);
printf("The data of link =:\n");
while(q!=NULL)
{
printf("%d\t",q->data);
q=q->next;
}
printf("\n");
getch();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?