# 链表的简单操作

#include<iostream>
using namespace std;
typedef struct node{
int num;
node * next;
}Node;

int flag=1;
Node *p=new node;
p->num=m;
p->next=NULL;
if(n->num > p->num)
{
n->num=p->num-1;
}

while(n!= NULL && n->num < p->num) {
n1=n;
n=n->next;
}
n1->next=p;
p->next=n;

return flag;
}

{
while(n->next != NULL)
{
if(n->next->num == m)
return 1;
n=n->next;
}
return 0;
}

{

int flag=0;
{
cout<<"该链表为空链表，不能删除";
}
while(n !=NULL && n->num != m){
n1=n;
n=n->next;
}
if(n!=NULL){
if(n->num == m){
n1->next=n->next;
delete n;
flag=1;
cout<<m<<"已经被删除了！"<<endl;
}
else
flag=0;
}
return flag ;
}
/*打印菜单指令*/
void instructions(void)
{
<<"1 插入一个元素到链表中./n"
<<"2 从链表中删除一个数./n"
<<"3  输入一个数查找是否存在./n"
<<"4  查看链表长度./n"
<<"5  结束退出./n"<<endl;

}

cout<<"当前链表数为:"<<endl;
while(no->next != NULL){
cout<<no->num<<"-->";
no=no->next;
}
cout<<no->num<<endl;
}
return 1;
else return 0;

}
int len=0;
while(n->next!=NULL)
{
n=n->next;
len++;
}
return len;
}

int main()
{
system("color 4e");
int choice;
int item,item1;
instructions();/*显示菜单函数*/
cout<<"请选择:";
cin>>choice;
while( choice!=5)
{
switch(choice)
{
case 1:
cout<<"请输入你想要插入的链表数:";
cin>>item;
{
cout<<item<<"已经成功顺序地插入链表中!"<<endl;
}
break;
case 2:
cout<<"请输入你要删除的数";
cin>>item;
cout<<item<<"被删除！"<<endl;
}
else{
cout<<item<<"没有找到!"<<endl;
}
}
else cout<<"链表为空，请先输入链表数，再查找！"<<endl;
break;
case 3:
cout<<"Enter character to be found:";
cin>>item1;
cout<<"恭喜你，查找成功!"<<endl;
else cout<<item1<<" 没有被找到！"<<endl;
}
else cout<<"链表为空."<<endl;
break;
case 4:
break;
case 5:
cout<<"结束运行！";
exit(0);
break;

default :
cout<<"Invalid choice."<<endl;
instructions();
}
cout<<"请选择:";
cin>>choice;
}
cout<<"结束运行."<<endl;
return 0;
}

• 本文已收录于以下专栏：

举报原因： 您举报文章：链表的简单操作 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)