/****************************************************************************** * * * File: ou2.cc * * * $Log$ ******************************************************************************/ #include const int nil = 0; typedef int Type; //Här bör du nog ändra!! #ifndef __GNUG__ enum bool {false,true}; #endif class Node { friend class List; private: Type val; Node* next; Node (Type value, Node* item = 0) {val = value; next = item;} }; class List { public: Type first() {return list->val;} void rest(); void concat(Type); bool is_empty() {return (bool)(list == nil);} List() {list = nil;} ~List() ; void traverse(void (*p_func)(Type&)); void add_last(Type); // Till denna metod saknas kod !!!!!! void append(List& l); //Denna metod beror av add_last (som ju tyvaerr ...) private: Node* list; }; void List::concat(Type val) { Node* pt = new Node(val, list); list = pt; } void List::rest() { Node* pt = list; list = list -> next; delete pt; } List::~List() { Node* pt = list; while (pt) { Node* tmp = pt; pt = pt -> next; delete tmp; } } void List::traverse(void (*p_func)(Type&)){ Node* pt = list; while (pt) { (*p_func)(pt->val); pt = pt -> next; } } void List::append(List& l) { Node *pt = l.list; while (pt) { add_last(pt -> val); pt = pt -> next; } }