#include <stdio head;
.h>
#include }
ptr1=head;
<stdlib.h>
#include < while(num!=ptr1string.h>
->numstruct && stud_node ptr1->{
intnext!=NULL num;
){
ptr char name[2=ptr20];
1;
int score;
ptr1= structptr stud1->_node *nextnext;
;
};
struct }
if stud_node *(num==ptrCreate_Stu1->num_Doc();//新建链){
if表
struct(ptr1== stud_node *head){
InsertDoc(struct head=ptr stud_node *1->nexthead,struct;
}
stud_node * else{
stud);//插 ptr2入->
structnext= stud_nodeptr1-> *DeleteDoc(struct stud_node *head,int numnext;
}
printf);//删除
void("\nDelete Print_Stu:%d\n_Doc",num);
(struct stud_node free(ptr *head);//1);
遍历
}
elseint main()
{
printf{
struct("\n%d stud_node *head not been found,*p;
int!\n", choice,num,snum);
core;
}
return char name[ head;
}
20];
//遍历 int size=
void Printsizeof(struct stud_Stu_D_node);
oc(struct stud do{
_node *head printf("1)
{
: Create struct stud_node2:Insret 3 *ptr;
:Delete ptr=head4:Print;
if 0:Exit\n");
(head==NULL scanf("%){
printfd",&choice("\nList);
switch is empty!\(choice){
n");
case 1 }
else:
head=Create_St{
printf("\nNowu_Doc();
break;
case 2:
p=(struct stud_node,These %d records are:\n*)malloc",(sizeptr->num);
printf("Num\tName\tScore);
printf\n");
("Input num while(ptr!=,name and scoreNULL){
:\n");
printf("%d scanf("%\t%s\td%s%d%d\n",",&num,name,&score);
ptr->num p->,ptr->num=num;
name,ptr strcpy(p->score);
->name,name ptr=);
p->ptr->nextscore=score;
;
}
head=Insert }
}
Doc(head,p--相关问题);
break--:
;
case 3:
printf("Input num\n");
scanf("%d",&num);
head=DeleteDoc(head,num);
break;
case 4:
Print_Stu_Doc(head);
break;
case 0:
break;
}
}while(choice!=0);
return 0;
}
//新建链表
struct stud_node *Create_Stu_Doc()
{
struct stud_node *head,*p;
int num,score;
char name[20];
int size=sizeof(struct stud_node);
head=NULL;
printf("Input num,name and score:\n");
scanf("%d%s%d",&num,name,&score);
while(num!=0){
p=(struct stud_node*)malloc(size);
p->num=num;
strcpy(p->name,name);
p->score=score;
head=InsertDoc(head,p);
scanf("%d%s%d",&num,name,&score);
}
return head;
}
struct stud_node *InsertDoc(struct stud_node *head,struct stud_node *stud )
{
struct stud_node *ptr,*ptr1,*ptr2;
ptr2=head;
ptr=stud;
//原链表为空时插入
if(head==NULL){
head=ptr;
head->next=NULL;
}
else{
while(ptr2!=NULL && ptr->num>ptr2->num){
ptr1=ptr2;
ptr2=ptr2->next;
}
if(ptr->num<=ptr2->num){
if(head==ptr2) head=ptr;
else ptr1->next=ptr;
ptr->next=ptr2;
}
else{
ptr2->next=ptr;
ptr->next=NULL;
}
}
return head;
}
//删除操作
struct stud_node *DeleteDoc(struct stud_node *head,int num)
{
struct stud_node *ptr1,*ptr2;
//要被删除节点为表头结点
while(head!=NULL && head->num==num){
ptr2=head;
head=head->next;
free(ptr2);
}
if(head==NULL){
return NULL;
}
//要被删除节点为非表头节点
ptr1=head;
ptr2=head->next;//从表头的下一节点搜索所有符合删除的节点
while(ptr2!=NULL){
if(ptr2->num==num){
ptr1->next=ptr2->next;
free(ptr