Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node {
- int data;
- node* next;
- };
- void recursion(node*);
- int main() {
- node* head = new node;
- node* ichi = new node;
- node* ni = new node;
- node* san = new node;
- node* shi = new node;
- node* go = new node;
- head->data = 10; //example given linked list para akon la
- ichi->data = 20; //10, 20, 30, 40, 50
- ni->data = 30;
- san->data = 40;
- shi->data = 50;
- head->next = ichi;
- ichi->next = ni;
- ni->next = san;
- san->next = shi;
- shi->next = go;
- go->next = NULL;
- recursion(head);
- return 0;
- }
- void recursion(node* root) { //an test b example code kanina na kailangan ig debug and explain
- if (root == NULL) {
- return;
- }
- recursion(root->next); //recursion anay means looping anay bago output data
- cout << root->data << ' '; //output then return looping here
- } //output should be in reverse which is 50, 40, 30, 20, 10
- //don't forget to take the NULL before output the numbers
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement