forked from ArsalanKhairani/Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayStack.h
58 lines (50 loc) · 1.31 KB
/
ArrayStack.h
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
/*******************************************************************************
* Copyright(c) Arsalan Khairani, 2014 *
* Stack *
* Using Array *
* *
* Generic array implementation of Stack. *
* Based on Array List implementation. *
*******************************************************************************/
#pragma once
#include "arraylist.h"
template < typename ARRAYTYPE >
class ArrayStack :
public ArrayList<ARRAYTYPE>
{
ARRAYTYPE* stackPointer;
int total;
int filled;
public:
ArrayStack ()
{
total = 10;
filled = 0;
array = new (ARRAYTYPE [total]);
stackPointer = array;
}
//add an item to the top of the stack
void Push(ARRAYTYPE item)
{
InsertItem(filled, item);
stackPointer = &stackPointer[++filled];
}
//remove an item from the top of the stack
ARRAYTYPE Pop()
{
stackPointer = &stackPointer[filled];
return DeleteItem(--filled);
}
//display whole array Stack
void DisplayArrayStack()
{
cout << endl;
for (int i = filled-1; i>=0; i--)
{
cout << array[i] << " ";
}
}
~ArrayStack(void)
{
}
};