File: stacklis.h

package info (click to toggle)
bcpp 0.0.20050725-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, lenny, squeeze
  • size: 680 kB
  • ctags: 336
  • sloc: cpp: 4,410; sh: 2,871; makefile: 179
file content (112 lines) | stat: -rw-r--r-- 3,910 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
// $Id: stacklis.h,v 1.3 2005/04/10 18:31:14 tom Exp $
#ifndef _STACK_LIST_HEADER
#define _STACK_LIST_HEADER

// Code written by Steven De Toni ACBC 11
// This header definition contains information of the construction,
// operation of a container class that holds data in linked list
// in stack form.

#include <stdio.h>              // NULL Constant
#include "anyobj.h"             // use Base class definition


// Structure definition used to link the items in the stack
struct ListLink
{
      ListLink*   pLinkedItem;  // linker (pointer to next item in the list)
      ANYOBJECT*  pItem;        // variable used to contain the data
};

class StackList : public ANYOBJECT
{
    protected:
        ListLink*     pCurrentPos;        // pointer to the end of the list
        int           itemCount;          // number of items in list
        int           spaceAvailable;     // used to test if memory
                                            // is still available
    public:
        //#### Constructors

        // Initialise internal variables.
        //
        StackList       (void);

        // Initialise variables, and place item passed in a new list
        //
        // Parameters:
        //     pItem    : Pointer to the object that is will to be stored.
        //                Item must be of descendant ANYOBJECT.
        //
        StackList       (ANYOBJECT* pItem);

        // use the defaults here:
        StackList(const StackList&);
        StackList& operator=(const StackList&);

        //#### Access Methods
        // Places a new item in the list (i.e on the stack).
        //
        // Parameters:
        //     pItem    : Pointer to the object that is will to be stored.
        //                Item must be of descendant ANYOBJECT.
        //
        // Return Values:
        //     int      : Returns a error code value to indicate whether operation
        //                was successful or not.
        //                Value:
        //                0  =  No Worries, item stacked.
        //               -1  =  Item not stacked, memory allocation failure
        //
        int        push            (ANYOBJECT* pItem);

        // Removes a item from the list and returns the value contained within it
        // back to the user. A NULL value is returns if there are no more items
        // within the list.
        //
        // Return Values:
        //     ANYOBJECT* : Pointer to the object last object that was placed
        //                  on the stack. Returns NULL pointer if operation
        //                  failed.
        //
        ANYOBJECT* pop             (void);

        // Peeks at items within the linked list without removing
        // them from the list.
        //
        // Parameters:
        //    int item :     item number in list.
        //
        // Return Values:
        //   ANYOBJECT*  : Returns NULL if operation failed, else
        //                 pointer to the object contained at list
        //                 number selected!
        //
        ANYOBJECT* peek (int item);

        // Returns the number of items current being stacked.
        //
        // Returns Values:
        //     int :    Num of items within queue.
        //
        int        status          (void);

        // Method returns whether last operation failed due to memory allocation
        // failure.
        //
        // Return Values:
        //     int  : Returns 1 of two values ...
        //            Values:
        //              0  =  memory available
        //             -1  =  Last memory allocation failed.
        //
        int        space           (void);

        //#### Destructor
        // Method will remove all list items from memory if they still exist,
        // no garbage collection provided, or used.
        //
        ~StackList                 (void);
};

#endif