#include "stdlib.h"
#define NULL 0
#define LEN sizeof(struct student)
struct student
{ long num;
struct student *next ;
} ;
int length;
struct student *create()
{ struct student *head1,*p1,*p2;
length=0;
head1=NULL;
printf("enter the list data,end with fushu :\n");
p1=(struct student*)malloc(LEN);
scanf("%ld",&p1->num);
p1->next=NULL;
while(p1->num>=0)
{++length;
if(length==1)
head1=p1;
else
p2->next=p1;
p2=p1;
p1=(struct student*)malloc(LEN);
scanf("%ld",&p1->num);
p1->next=NULL;
}
free(p1);
return(head1);
}
struct student *insert(struct student *head,struct student *stud)
{ struct student *p0,*p1,*p2;
p1=head;
p0=stud;
if(head==NULL)
{ head=p0;
p0->next=NULL;
}
else
while((p0->num>p1->num)&&(p1!=NULL))
{p2=p1;
p1=p1->next;
}
if(head==p1)
{p0->next=head;
head=p0;
}
else
{p2->next=p0;
p0->next=p1;
}
++length;
return(head);
}
struct student *delete(struct student *head,long num)
{ struct student *p1,*p2;
if(head==NULL)
{printf("\nLIST NULL!!!\n");
return(head);
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{ p2=p1;
p1=p1->next;
}
if(num==p1->num)
{ if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("the delete number is:%ld\n",num);
free(p1);
length--;
}
else
printf("%ld not been found!\n",num);
return(head);
}
struct student *find(struct student *head,long num)
{ struct student *p1,*p2;
int i;
if(head==NULL)
{printf("\n LIST NULL!!!\n");
return(head);
}
p1=head;
while(num!=p1->num&&p1!=NULL)
{i=1;
p2=p1;
p1=p1->next;
i++;
}
if(p1!=NULL)
printf("the find number is:%d\n",i);
else
printf("%ld not been found!\n",num);
return(head);
}
void print(struct student *head)
{ struct student *p4;
if(head==NULL)
printf("LIST NULL!!!\n");
else
printf("\n Now,these %d nodes are:\n",length);
p4=head;
if(head!=NULL)
do
{ printf("%ld\n",p4->num);
p4=p4->next;
} while(p4!=NULL);
}
struct student *clear(struct student *head)
{ struct student *p1;
int i;
p1=head;
if(head==NULL)
{ printf("\nLIST NULL!!!\n");}
else
for(i=1;i<=length;i++)
{ p1->num=0;
p1=p1->next;
}
return(head);
}
void menu()
{
printf("\n\n\n\n\n");
printf(" |-----------------------|\n");
printf(" | Input the choose |\n");
printf(" |-----------------------|\n");
printf(" | 1--print |\n");
printf(" | 2--find |\n");
printf(" | 3--delete |\n");
printf(" | 4--insert |\n");
printf(" | 5--clear |\n");
printf(" | 0--break |\n");
printf(" |-----------------------|\n");
}
void main()
{ struct student *head,*stud;
long num1,num2;
char yes_no;
int in_num;
head=create();
do
{ menu();
printf("choose the list number: ");
scanf("%d",&in_num);
switch(in_num)
{ case 1: print(head); break;
case 2: {printf("\n please enter the number you want to find:\n");
scanf("%ld",&num1);
find(head,num1);}; break;
case 3: {printf("\n please enter the number you want to delete:\n");
scanf("%ld",&num2);
head=delete(head,num2);
print(head);}; break;
case 4: { printf("enter the number you want to insert:\n");
stud=(struct student *)malloc(LEN);
scanf("%ld",&stud->num);
head=insert(head,stud);
print(head);}; break;
case 5: head=clear(head); print(head); break;
case 0: break;
default: printf("error\n");
}
printf("\nchoose again?(y(Y) or n(N)) ");
yes_no=getche();
printf("\n\n");
} while(yes_no=='Y' || yes_no=='y');
exit(1);
}

lanys2008
- 粉丝: 3
最新资源
- 项目管理中的常见授权技巧(二).docx
- 基于网络环境下图书馆知识型人才的管理.docx
- PLC六路抢答器课程设计.doc
- 电气自动化工程中的节能设计技术.docx
- 网络环境下的学术期刊编辑工作改革分析.docx
- IBM基于企业战略的人力资源战略.doc
- 【无人机技术】基于四旋翼无人机的软夹爪抓取系统设计与实现:动力学建模、自适应控制及ROS抓取仿真(论文复现含详细代码及解释)
- 实验四oracle对象管理及使用.doc
- 【区域经济学】基于泰尔指数的公共文化服务均等化评估:2013-2019年中国31省份数据分析与政策建议(论文复现含详细代码及解释)
- java程序设计方案基础第十章第一题.doc
- 电力电子基于图腾柱软开关PFC电路的AC-DC变换器研究:高效率变换器设计与实现(论文复现含详细代码及解释)
- 从传统网络架构到SDN化演进方案.docx
- 中移铁通通信作业安全手册.docx
- 基于iSTEM教育的PBL网络营销课程设计.docx
- 适配服务信任机制与区块链技术结合-洞察研究.pptx
- 土木工程基于微预应力-固结理论的早龄期混凝土高温拉伸徐变模型:温度与湿度耦合效应的数值模拟及工程应用(论文复现含详细代码及解释)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈


