home *** CD-ROM | disk | FTP | other *** search
/ Quark 3 / Quark3.iso / KATALOG / ARCHIV / TOOL / T001.ZIP / SOURCE.ZIP / nsequence.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-27  |  3.7 KB  |  111 lines

  1. /*
  2. Copyright (C) Matthew 'pagan' Baranowski & Sander 'FireStorm' van Rossen
  3.  
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License
  6. as published by the Free Software Foundation; either version 2
  7. of the License, or (at your option) any later version.
  8.  
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. GNU General Public License for more details.
  13.  
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software
  16. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  17. */
  18.  
  19. /*
  20.  linked list implementation, by Matthew Baranowski
  21. */
  22.  
  23. #ifndef _NPSEQUENCE_H_
  24. #define _NPSEQUENCE_H_
  25.  
  26. #define Object void *
  27.  
  28. #ifndef NULL
  29. #define NULL 0
  30. #endif
  31.  
  32. typedef class NodePositionInfo                  * NodePosition;
  33. typedef class NodeSequenceInfo                  * NodeSequence;
  34.                      
  35. /********************************************************************
  36.  * CLASS NAME: NodePosition
  37.  * double linked nodeNodePosition implementation 
  38.  ********************************************************************/
  39.  
  40.  
  41. class NodePositionInfo {
  42.     private:
  43.         NodeSequence container_;
  44.         Object    element_;
  45.         NodePosition  nextNode_;
  46.         NodePosition  prevNode_;
  47.         
  48.     public:
  49.         NodePositionInfo( NodeSequence container, Object element )
  50.                 { container_ = container; element_ = element; };
  51.         
  52.         void setNextNode( NodePosition nextNode ) { nextNode_ = nextNode; };
  53.         void setPrevNode( NodePosition prevNode ) { prevNode_ = prevNode; };
  54.         NodePosition getNextNode() { return nextNode_; };
  55.         NodePosition getPrevNode() { return prevNode_; };
  56.         void setElement( Object element ) { element_ = element; };        
  57.         NodeSequence container() { return container_; };
  58.         Object    element() { return element_; };
  59. };
  60.         
  61. /********************************************************************
  62.  * 
  63.  * CLASS NAME: NodeSequence
  64.  *
  65.  * double linked node sequence implementation
  66.  * 
  67.  ********************************************************************/
  68.  
  69.  
  70. class NodeSequenceInfo {
  71.  
  72.     private:
  73.         NodePosition first_;
  74.         NodePosition last_;
  75.         int size_;
  76.         
  77.     public:
  78.         NodeSequenceInfo() { size_ = 0; first_ = last_ = NULL; };
  79.         ~NodeSequenceInfo();
  80.  
  81.         void clearSequence() { size_ = 0; first_ = last_ = NULL; };
  82.         NodeSequence newContainer() { return new NodeSequenceInfo(); };
  83.         int isEmpty() { if (size_ == 0) return 1; else return 0;};
  84.         int size() { return size_; };
  85.         Object replace(NodePosition, Object newElement );
  86.         void  swap(NodePosition p1,NodePosition p2 );
  87.         NodePosition first() { return first_; };
  88.         NodePosition last() { return last_; };
  89.         NodePosition before(NodePosition p );
  90.         NodePosition after(NodePosition p );
  91.         NodePosition insertFirst( Object element );
  92.         NodePosition insertLast( Object element );
  93.     NodePosition insertFirst( NodePosition nP );
  94.     NodePosition insertLast( NodePosition nP );
  95.         NodePosition insertBefore(NodePosition p, Object element );
  96.         NodePosition insertAfter(NodePosition p, Object element );
  97.         Object   remove(NodePosition p );
  98.         Object   removeAfter(NodePosition p );
  99.         Object   removeBefore(NodePosition p );
  100.         Object   removeFirst();
  101.         Object   removeLast();
  102.     void dumpSequence();
  103. };
  104.  
  105. #endif
  106.  
  107.  
  108.     
  109.  
  110.  
  111.