#include
#include
using namespace std;
struct list
{
int num;
list *next;
};
list *head=NULL;
list *end=NULL;
list *Createlist()
{
list *p;
p=new list;
head=p;
end=p;
cout<<"请输入接点数,以零结束:"< cin>>p->num;
while (p->num!=0)
{
end->next=p;
end=p;
p=new list;
cin>>p->num;
}
delete p;
end->next=NULL;
return head;
}
void findlist(list *head)
{
list *p;
int n=0,sum=0;
p=head;
cout<<"请输入你要查询的接点:"< cin>>n;
while (p)
{
if (p->num==n)
{
sum++;
}
p=p->next;
}
cout<<"接点数目是"<}
void dellist(list *head)
{
list *p;
p=head;
int n;
cout<<"请输入您要删除的接点位置:"< cin>>n;
while (n {
p=p->next;
}
p->next=p->next->next;
}
void showlist(list *head)
{
while (head)
{
cout<num<<" ";
head=head->next;
}
}
void main ()
{
string str;
begin:
cout<<"1->增加链表 2->显示链表 3->删除节点 4->查询接点 5->推出程序";
cout< cin>>str;
if (str[0]=='1')
{
Createlist();
getchar();
system("cls");
goto begin;
}
else if (str[0]=='2')
{
if (head==NULL)
{
cout<<"接点为空,请先建立链表:"< getchar();
getchar();
system("cls");
goto begin;
}
showlist(head);
getchar();
getchar();
system("cls");
goto begin;
}
else if (str[0]=='3')
{
if (head==NULL)
{
cout<<"接点为空,请先建立链表:"< getchar();
getchar();
system("cls");
goto begin;
}
dellist(head);
getchar();
getchar();
system("cls");
goto begin;
}
else if (str[0]=='4')
{
if (head==NULL)
{
cout<<"接点为空,请先建立链表:"< getchar();
getchar();
system("cls");
goto begin;
}
findlist(head);
getchar();
getchar();
system("cls");
goto begin;
}
else if(str[0]=='5')
{
exit(-1);
}
else
{
cout<<"输入错误,请重新输入:"< getchar();
system("cls");
goto begin;
}
}
--------------------next---------------------
阅读(1229) | 评论(0) | 转发(0) |