Advertisement
RobertDeMilo

Hindu Recursions

Dec 12th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. void Print(Node *p)
  2. {
  3.     if (p == nullptr)
  4.     {
  5.         cout << endl;
  6.         return;
  7.     }
  8.     cout << p->data;
  9.     Print(p->next);
  10. }
  11.  
  12. void ReversePrint()
  13. {
  14.     if (p == nullptr)
  15.     {
  16.         return;
  17.     }
  18.     ReversePrint(p->next);
  19.     cout << p->data;
  20. }
  21.  
  22. void Reverse(Node* p)
  23. {
  24.     if (p->next==nullptr)
  25.     {
  26.         head = p;
  27.         return;
  28.     }
  29.     Reverse(p->next);
  30.  
  31.     /*Node* q = p->next;
  32.     q->next = p;*/
  33.     p->next->next = p;
  34.     p->next = nullptr;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement