Repository navigation
Expand file tree
/
Copy pathDStack.h
More file actions
executable file
·47 lines (38 loc) · 1.62 KB
/
Copy pathDStack.h
File metadata and controls
executable file
·47 lines (38 loc) · 1.62 KB
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
/****************************************************************************
* Joel Brigida
* COP3530: Data Structures
* This header file defines a Stack data type.
* Basic operations:
* constructor: Constructs an empty stack
* empty: Checks if a stack is empty
* push: Modifies a stack by adding a value at the top
* top: Accesses the top stack value; leaves stack unchanged
* pop: Modifies stack by removing the value at the top
* display: Displays all the stack elements
* Class Invariant:
* 1. The stack elements (if any) are stored in positions 0, 1, . . ., myTop of myArray.
* 2. -1 <= myTop < myCapacity
****************************************************************************/
#include <iostream>
using namespace std;
#ifndef DSTACK
#define DSTACK
typedef int StackElement;
class Stack
{
public: /***** Function Members *****/
Stack(int numElements = 128); /***** Constructors *****/
Stack(const Stack& original);
~Stack(); /***** Destructor *****/
Stack & operator= (const Stack& original); /***** Assignment *****/
bool empty() const;
void push(const StackElement& value);
void display(ostream& out) const;
StackElement top() const;
void pop();
private:
int myCapacity, // capacity of stack
myTop; // top of stack
StackElement *myArray; // dynamic array to store elements
}; // end of class declaration
#endif