cpp2html 0.1-alpha © 2002 Andrea Leofreddi. To get the source click here

// esercizio 1: Linked List

class Data {
	private:
		int data; // dato della class
	public:
		int get_data() { return data; };

		Data(int ndata)
		: data(ndata) { };
};

class LinkedList {
	public:
		class ListNode; // predefinizione

	private:
		ListNode *head;

	public:
		class ListNode {
			public:
				Data data;
				ListNode *next;

				ListNode(const Data &copy)
				: data(copy), next(NULL) { };
				ListNode(const Data &copy, ListNode *nnext)
				: data(copy), next(nnext) { };
		};

		// membri statici
		static const int exception_empty;

		// push
		void push(const Data &nelement) {
			ListNode *newnode = new ListNode(nelement, head);
			head = newnode;
		}

		// pop
		Data pop() {
			if(!head)
				throw exception_empty;

			ListNode *p = head;
			head = head->next;
		}

		ListNode *get_head() {
			return head;
		}

		ListNode *get_tail() {
			ListNode *p;

			for(p = head; p->next; p = p->next);
			return p;
		}

		LinkedList()
		: head(NULL) { };
};

// Inizializzazione delle static
const int LinkedList::exception_empty = 0x1;