#include <iostream>
using namespace std;

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

class CircularLinkedList
{
public:
	Node* head;

	CircularLinkedList()
	{
		head = NULL;
	}

	~CircularLinkedList()
	{
		if (head)
		{
			Node *temp = head;
			do
			{
				Node *next = temp->next;
				delete temp;
				temp = next;
			}
			while (temp != head);
		}
	}

	void appendNode(int newVal)
	{
		Node** temp = &head;
		if (head) {
			do {
				temp = &((*temp)->next);
			}
			while (*temp != head);
		}
		*temp = new Node;
		(*temp)->data = newVal;
		(*temp)->next = head;
	}

	void displayData()
	{
		if (head)
		{
			Node* temp = head;
			do
			{
				cout << temp->data << " ";
				temp = temp->next;
			}
			while (temp != head);
		}
	}	
};

int main()
{
	CircularLinkedList c;
	c.appendNode(10);
	c.appendNode(20);
	c.displayData();

	return 0;
}