Homework 37

Modify the following code so the function printList prints the data fields of the linked list from back to front.

class Node
{
public:
  int data;
  Node* next;
};

 

void printList(Node* p) {
    if (p!=0){
        cout << p ->data << endl;
        printList(p->next);
    }
}