|
|
1.1 ! root 1: ! 2: struct link { ! 3: link* next; ! 4: common* p; ! 5: link(common* pp, link* nn) { p=pp; next=nn; } ! 6: }; ! 7: ! 8: class list : public common { /* an element can occur more than once */ ! 9: link* head; ! 10: link* tail; ! 11: public: ! 12: list() { head = tail = 0; } ! 13: list(common& oo) { head = tail = new link(&oo, 0); } ! 14: ~list(); ! 15: ! 16: void add(common& oo) { ! 17: head = new link(&oo,head); ! 18: if (tail == 0) tail=head; ! 19: } ! 20: ! 21: void addlast(common& oo) { ! 22: if (tail==0) ! 23: head = tail = new link(&oo,0); ! 24: else ! 25: tail = tail->next = new link(&oo,0); ! 26: } ! 27: ! 28: common* remove() { ! 29: if (head) { ! 30: common* p = head->p; ! 31: if (head == tail) ! 32: head = tail = 0; ! 33: else ! 34: head=head->next; ! 35: return p; ! 36: } ! 37: else ! 38: return 0; ! 39: } ! 40: ! 41: common* remove(common& oo); ! 42: common* first() { return head?head->p:0; } ! 43: common* last() { return tail?tail->p:0; } ! 44: int empty() { return head!=0; } ! 45: }; ! 46: ! 47: class set : public list { /* unique elements */ ! 48: common remove(); ! 49: public: ! 50: set(); ! 51: set(common&); ! 52: ~set(); ! 53: ! 54: int empty(); ! 55: int insert(common&); ! 56: common* remove(common&); ! 57: common* find(char*); ! 58: common* find(common&); ! 59: int no_of_mem(); ! 60: }; ! 61: ! 62: struct dlink { ! 63: dlink* pre, *suc; ! 64: common* p; ! 65: dlink(dlink* pr, dlink* su, common* pp) { pre=pr; suc=su; p=pp; } ! 66: }; ! 67: ! 68: class dlist : public common { ! 69: dlink* head; ! 70: public: ! 71: dlist(); ! 72: dlist(common&); ! 73: ~dlist(); ! 74: ! 75: void insert(); ! 76: common* remove(); ! 77: common* remove(common&); ! 78: common* curr(); ! 79: common* next(); ! 80: common* prev(); ! 81: }; ! 82:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.