Skip to content

Commit

Permalink
Merge pull request #1 from khavinshankar/reverse-function-to-linked-list
Browse files Browse the repository at this point in the history
Update Linked List.cpp
  • Loading branch information
khavinshankar authored Aug 7, 2019
2 parents c071083 + 5db2683 commit 19df162
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions Data Structure/Linked List.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 choice, x;
Expand All @@ -101,9 +115,10 @@ int main()
cout<<"\n2. Delete";
cout<<"\n3. Search";
cout<<"\n4. Print";
cout<<"\n5. Reverse";
cout<<"\n0. Exit";
cout<<"\n\nEnter you choice : ";
cin>>choice;
cin>>choice;
switch (choice)
{
case 1 : cout<<"\nEnter the element to be inserted : ";
Expand All @@ -115,8 +130,11 @@ int main()
case 3 : cout<<"\nEnter the element to be searched : ";
cin>>x;
search(x); break;
case 4 : show();
cout<<"\n"; break;
case 4 : show();
cout<<"\n"; break;
case 5 : cout<<"The reversed list: \n";
reverse(); show();
cout<<"\n"; break;
}
}
while(choice!=0);
Expand Down

0 comments on commit 19df162

Please sign in to comment.