Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Node
- {
- int data;
- struct Node* next;
- } *first = NULL;
- void add(int data)
- {
- if(first == NULL)
- {
- first = new struct Node;
- first->data = data;
- first->next = NULL;
- return;
- }
- struct Node* p = first;
- while(p->next)
- {
- p = p->next;
- }
- struct Node* t = new struct Node;
- p->next = t;
- t->data = data;
- t->next = NULL;
- }
- void display(struct Node *p)
- {
- while(p)
- {
- cout << p->data << endl;
- p = p->next;
- }
- }
- void reverseLL(struct Node*q, struct Node*p )
- {
- if (p)
- {
- reverseLL(p, p->next);
- p->next = q;
- }
- else
- first = q;
- }
- int main()
- {
- add(10), add(20), add(30);
- display(first);
- reverseLL(NULL, first);
- display(first);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement