diff --git a/README.md b/README.md index 96267c0..72197e6 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,20 @@ # DATA-STRUCTURES -_IMPLIMENTATION OF DS PROGRAMMES_ +_IMPLIMENTATION OF DS_ALGO PROGRAMMES_ ## Language - C++ ## INCLUDES:- + ### Data Structures - ARRAY - LINKED LIST - QUEUE - STACK + - GRAPH + + ### Algorithms - Searches - Sorting - Hashing - - Graphs. - diff --git a/linkedlist/Reverse_linked_list.cpp b/linkedlist/Reverse_linked_list.cpp new file mode 100644 index 0000000..56b05ca --- /dev/null +++ b/linkedlist/Reverse_linked_list.cpp @@ -0,0 +1,88 @@ +#include +#include +#include +using namespace std; + +// Creating a NODE Structure +struct node +{ + int data; // data + node *next; // link to next node +}; + +// Creating a class LIST +class list +{ + node *start; + public: + void create(); // to create a list + void show(); // show + void reverse(list); // Reverse the list +}; + +// Main function +int main() +{ + list l1; + cout<<"Enter Elements in ascending order."; + l1.create(); // to create a first list + cout<<"Original List : "<>no; + cout<<"Enter "<>value; + new_node=new node; + new_node->data=value; + new_node->next=NULL; + if(start==NULL) + start=new_node; + else + pre_node->next=new_node; + pre_node=new_node; + } +} + +// Displaying LIST +void list::show() +{ + struct node *ptr=start; + cout<<"\nThe List is : "; + while(ptr!=NULL) + { + cout<data<<" -> "; + ptr=ptr->next; + } + cout<<"NULL"; +} + +void list::reverse(list& l2) +{ + struct node *prevNode = NULL, *currNode = l2, *nextNode = NULL; + + while(currNode != NULL) + { + nextNode = currNode->next; + currNode->next = prevNode; + prevNode = currNode; + currNode = nextNode; + } + + l2 = prev; +}