Update Linked List.cpp

This commit is contained in:
Khavin Shankar 2019-08-07 07:04:58 +05:30 committed by GitHub
parent c071083afe
commit 5db2683566
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -92,6 +92,20 @@ void show()
} }
void reverse(){
node* first = start;
node* second = first->next;
while(second != NULL){
node* tem = second->next;
second->next = first;
first = second;
second = tem;
}
start->next = NULL;
start = first;
}
int main() int main()
{ {
int choice, x; int choice, x;
@ -101,9 +115,10 @@ int main()
cout<<"\n2. Delete"; cout<<"\n2. Delete";
cout<<"\n3. Search"; cout<<"\n3. Search";
cout<<"\n4. Print"; cout<<"\n4. Print";
cout<<"\n5. Reverse";
cout<<"\n0. Exit"; cout<<"\n0. Exit";
cout<<"\n\nEnter you choice : "; cout<<"\n\nEnter you choice : ";
cin>>choice; cin>>choice;
switch (choice) switch (choice)
{ {
case 1 : cout<<"\nEnter the element to be inserted : "; case 1 : cout<<"\nEnter the element to be inserted : ";
@ -115,8 +130,11 @@ int main()
case 3 : cout<<"\nEnter the element to be searched : "; case 3 : cout<<"\nEnter the element to be searched : ";
cin>>x; cin>>x;
search(x); break; search(x); break;
case 4 : show(); case 4 : show();
cout<<"\n"; break; cout<<"\n"; break;
case 5 : cout<<"The reversed list: \n";
reverse(); show();
cout<<"\n"; break;
} }
} }
while(choice!=0); while(choice!=0);