#include<iostream>
using namespace std;
class Node
{
public:
int value;
Node *next;
};
class LinkedList
{
private:
// head always points to the first node
// If there is no node, then head is NULL
Node *head;
public:
LinkedList()
{
head=NULL;
}
// Adds a node containing the passed
// value at the end of the list
void appendNode(int val)
{
Node *n = new Node;
n->value = val;
n->next = NULL;
if(head==NULL)
{
head=n;
}
else
{
Node *p = head;
while(p->next!=NULL)
{
p=p->next;
}
p->next = n;
}
}
void deleteAllNodes()
{
deleteAllNodesRecursive(head);
}
void deleteAllNodesRecursive(Node *n)
{
// complete this function
}
void printList()
{
printListRecursive(head);
}
void printListRecursive(Node *n)
{
// complete this function
}
int countNodes()
{
return countNodesRecursive(head);
}
int countNodesRecursive(Node *n)
{
// complete this function
return -1;
}
};
int main()
{
// DO NOT CHANGE THE MAIN FUNCTION
LinkedList L;
L.appendNode(3);
L.appendNode(5);
L.appendNode(7);
L.appendNode(2);
L.printList(); // Should print 3->5->7->2->
cout << L.countNodes() << endl; // Should print 4
L.deleteAllNodes();
L.printList(); // Should print nothing
}