#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef strUCt elem/*定义接点*/
{
char name[10];
struct elem *next;
}create;
create *head,*van,*cur,*temp;/*定义头接点(head),前驱接点(van),当前接点(cur),零时接点(temp)*/
void menu()/*创建菜单*/
{
printf("\t\t\t1.创建新链表------[1]\n");
printf("\t\t\t2.插入新元素------[2]\n");
printf("\t\t\t3.删除旧元素------[3]\n");
printf("\t\t\t4.查找旧元素------[4]\n");
printf("\t\t\t5.倒置原链表------[5]\n");
printf("\t\t\t6.显示所有元素----[6]\n");
printf("\t\t\t7.退出------------[7]\n\n");
printf("请选择(1~7): ");
}
void new(int n)/*创建新链表,参数n为链表长度*/
{
int i;
printf("\n");
if((head=(create *)malloc(sizeof(create)))==NULL)/*定义头接点*/
{
printf("\n不能创建链表");
exit(1);
}
van=head;/*将前驱接点指针指向头接点*/
for(i=1;i<=n;i++)
{
if((cur=(create *)malloc(sizeof(create)))==NULL)/*定义新接点*/
{
printf("\n不能创建链表");
exit(1);
}
cur->next=NULL;/*将当前接点的后继指针置空*/
van->next=cur;/*连接接点*/
printf("输入第%d个人的名字: ",i);
scanf("%s",&cur->name);/*输入当前接点的数据域内容*/
van=cur;
}
}