#ifndef _stdio_h #define _stdio_h stdio.h #include #endif #ifndef _linklist_h #define _linklist_h // General #define ON 1 #define OFF 0 // LinkedListNode typedef enum Bool {FALSE, TRUE}; template class Node { public: Node *prev, *next; // prev and next nodes double key; // ordering key T value; // the value a node includes Node () { next = prev = 0; key = 0; } Node (T val) { next = prev = 0; value = val; key = 0; } Node (T val, double keyval) { next = prev = 0; value = val; key = keyval; } ~Node () { if ( prev && next) { prev->next = next; next->prev = prev; // printf ("prev = %d,next = %d", prev, next); // getchar (); } else if (prev) prev->next = 0; else if (next) next->prev = 0; } } Node; template class LinkedList { private: Node *first, *last; int length, MaxLength; int chlen; // iz there length checking ? Node *current; public: LinkedList () { first = new Node ; last = new Node ; length = 0; MaxLength = 0; first->next = last; last->prev = first; chlen = OFF; // checking length off } LinkedList (int Len) { first = new Node ; last = new Node ; length = 0 ; MaxLength = Len; first->next = last; last->prev = first; chlen = ON; // checking length } ~LinkedList () { current = first->next; while (current != last) { if (!current->prev) Panic (); delete current->prev ; current = current->next; } delete current; } // ----------- methods------------ Bool Isempty (void); void CheckLength (int number); void Emptify (void); void Panic (void); // motion Bool Start (void); Bool End (void); Bool Forward (void); Bool Backward (void); T GetValue (void); double GetKey (void); // Find, Insert, Delete // if the list can be ordered void Insert (T value); Bool Delete (T value); Node *Find (T value); void Insert (T value, double key); Bool Delete (T value, double key); Node *Find (T value, double key); // if the list is not ordered void UnOrdInsert (T value); }; // definition of lists, containing main types //typedef LinkedList IntList; //typedef LinkedList FloatList; //typedef LinkedList DoubleList; //typedef LinkedList ShortList; //typedef LinkedList CharList; //typedef LinkedList StringList; #endif