未验证 提交 1e78677a 编写于 作者: A Ashwek Swamy 提交者: GitHub

Update Linked List.cpp

上级 16e1bcdb
......@@ -32,17 +32,33 @@ void insert(int x)
}
}
void remove(int x)
{
node *t=start;
node *p;
while(t->val!=x)
{
p=t;
t=t->next;
void remove(int x){
if( start == NULL ){
cout<<"\nLinked List is empty\n";
return ;
}
else if( start->val == x ){
node *temp = start;
start = start->next;
delete temp;
return ;
}
p->next=t->next;
delete t;
node *temp = start, *parent = start;
while( temp != NULL && temp->val != x ){
parent = temp;
temp = temp->next;
}
if( temp == NULL ){
cout <<endl <<x <<" not found in list\n";
return ;
}
parent->next = temp->next;
delete temp;
}
void search(int x)
......@@ -85,6 +101,7 @@ int main()
cout<<"\n2. Delete";
cout<<"\n3. Search";
cout<<"\n4. Print";
cout<<"\n5. Exit";
cout<<"\n\nEnter you choice : ";
cin>>choice;
switch (choice)
......@@ -99,6 +116,7 @@ int main()
cin>>x;
search(x); break;
case 4 : show(); break;
case 5 : exit(0);
}
}
while(choice!=0);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册