#include<stdio.h>
#include<windows.h>
#include<string.h>
typedef struct student
{
int num;
char name[10];
struct student *next;
}stud;
//创建链表
stud *creat();
//输出到文本文件
void display(stud *h);
//按num查找
void search(stud *h,int number);
//插入函数
stud *Insert(stud *h);
//按链表节点删除
stud* Del(stud *h);
//按num排序
void sort(stud *h);
//主菜单
void menu(void)
{
}
void main()
{
}
}
stud *creat()
{
void search(stud *h,int number)
{
}
stud* Insert(stud *h)
{
stud * Del(stud *h)
{
void display(stud *h)
{
void sort(stud *h)
{
display(first);
}
#include<windows.h>
#include<string.h>
typedef struct student
{
int num;
char name[10];
struct student *next;
}stud;
//创建链表
stud *creat();
//输出到文本文件
void display(stud *h);
//按num查找
void search(stud *h,int number);
//插入函数
stud *Insert(stud *h);
//按链表节点删除
stud* Del(stud *h);
//按num排序
void sort(stud *h);
//主菜单
void menu(void)
{
system("cls");
printf("|==========================================\n");
printf("| student's information list |\n");
printf("|==========================================\n");
printf("| [1] creat linklist |\n");
printf("| [2] search |\n");
printf("| [3] insert |\n");
printf("| [4] delete |\n");
printf("| [5] printf |\n");
printf("| [6] sort |\n");
printf("| [7] display |\n");
printf("|==========================================|\n");
printf("please input your choose(1-6)\n");
}
void main()
{
stud *h=NULL;
int choose,num;
while(1)
{
menu();scanf("%d",&choose);switch(choose){
}case 1:system("cls");h=creat();puts("\nLinklist created successfully!");system("pause");getchar();break;case 2:system("cls");printf("Input the student's num which you want to find!\n");scanf("%d",&num);search(h,num);puts("\npress any key to return...");getchar();getchar();break;case 3:system("cls");Insert(h);display(h);puts("\nPress any key to return...");getchar();getchar();break;case 4:system("cls");display(h);Del(h);display(h);puts("\nDelete successfully! press any key to return...");getchar();getchar();break;case 5:display(h);printf("Store successful\n");puts("\nPress any key to return...");getchar();getchar();break;case 6:printf("排序中。。。\n");sort(h);
system("pause");
printf("排序成功!\n");break;case 7:exit(0);break;default:system("cls");puts("Illegal letter! Press any key to return...");menu();getchar();
}
}
stud *creat()
{
FILE *fp;}
int n;
int i=0;
stud *h,*p,*s;
if((fp=fopen("D:\\stmessages.txt","a+"))==NULL)
{
printf("open error!");
exit (0);
}
puts("pleasa input Chain length of the table:");
scanf("%d",&n);
if((h=(stud *)malloc(sizeof(stud)))==NULL)
{
printf("no space!");
exit (0);
}
h->next=NULL;
p=h;
for(i=0;i<n;i++)
{
if((s=(stud *)malloc(sizeof(stud)))==NULL)
{
puts("no space!");
}
printf("\nplease input %d student's information:",i+1);
scanf("%d%s",&s->num,&s->name);
fprintf(fp,"%d\t%s\n",s->num,s->name);
p->next=s;
s->next=NULL;
p=s;
}
fclose(fp);
return h;
void search(stud *h,int number)
{
stud *p;
p=h->next;
puts("\nprintf search information of the search");
while(p!=NULL)
{
if(p->num==number)
{
printf("%d\t%s",p->num,p->name);
}
p=p->next;
}
}
stud* Insert(stud *h)
{
char InsertName[10];}
int n,InsertNum;
int j=0;
stud *p,*q;
p=h;
puts("please input position of the insert、student's num and name\n");
scanf("%d%d%s",&n,&InsertNum,InsertName);
while(p && j<n-1)
{
p=p->next;
j++;
}
q=(stud *)malloc(sizeof(stud));
q->num=InsertNum;
strcpy(q->name,InsertName);
q->next=p->next;
p->next=q;
q=q->next;
return h;
stud * Del(stud *h)
{
stud *p,*q;}
int n,j=0;
puts("please students's num of your delete:");
scanf("%d",&n);
p=q=h;
while(p && j<n-1)
{
p=p->next;
++j;
}
q=p->next;
p->next=q->next;
return h;
void display(stud *h)
{
FILE *fp;}
stud *p;
if((fp=fopen("d:\\GTBL2.txt","w"))==NULL)
{
printf("cat open the file!");
exit(0);
}
p=h->next;
while(p!=NULL)
{
fprintf(fp,"%d\t%s\n",p->num,p->name);
p=p->next;
}
fclose(fp);
void sort(stud *h)
{
stud *first,*tail,*p_min,*min,*p;}
first = NULL;
while (h != NULL)
{
for (p=h,min=h; p->next!=NULL; p=p->next)
{
if (p->next->num < min->num)
{
p_min = p;
min = p->next;
}
}
if (first == NULL)
{
first = min;
tail = min;
}
else
{
tail->next = min;
tail = min;
}
if (min == h)
{
h= h->next;
}
else
{
p_min->next = min->next;
}
display(first);
}