/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#ifndef LIST_H
#define LIST_H

#define BOOL int
#define TRUE 1
#define FALSE 0

//**********************************************************************
//
//  Class definitions:
//
//     LinkList : linked list
//     Queue    : queue
//     Stack    : stack
//
//**********************************************************************

// list element
struct list_elm { struct list_elm *Next;
                  struct list_elm *Prev;
                  void *Data; };

// linked list
class LinkList {
   private:
      // number of elements
      int NElm;
      // bottom of list
      struct list_elm *Bottom;
      // top of list
      struct list_elm *Top;
   public:
      // constructor
      LinkList();
      // destructor
      ~LinkList();
      // get number of elements
      inline int GetNElm() { return NElm; };
      // more elements
      inline BOOL MoreElm() { return (NElm>0); };
      // insert at the bottom
      void InsertBottom(void *p);
      // insert at the top
      void InsertTop(void *p);
      // remove from the bottom
      BOOL RemoveBottom();
      // remove from the top
      BOOL RemoveTop();
      // get from the bottom
      void *GetBottom();
      // get from the top
      void *GetTop();
      // turn list
      void Turn();
      // operators
      void *operator[](int ix);
   };

// queue
class Queue : public LinkList {
   private:
   public:
      // constructor
      Queue();
      // destructor
      ~Queue();
      // enqueue
      void EnQueue(void *p);
      // dequeue
      void *DeQueue();
   };

// stack
class Stack : public LinkList {
   private:
   public:
      // constructor
      Stack();
      // destructor
      ~Stack();
      // push
      void Push(void *p);
      // pop
      void *Pop();
   };

#endif // LIST_H
