-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
92 lines (81 loc) · 1.17 KB
/
Copy pathStack.cpp
File metadata and controls
92 lines (81 loc) · 1.17 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
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
#include <cstdlib>
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node* next;
};
class Stack
{
private:
Node* top1;
int count;
int maxnum;
public:
Stack(int max)
{
top1 = NULL;
maxnum = max;
count = 0;
}
void pop()
{
if(top1 == NULL)
cout << "Nothing on stack" << endl;
else
{
Node* toPop = top1;
top1 = top1->next;
count--;
delete(toPop);
}
}
void push(int input)
{
if(count == maxnum)
cout << "Stack is full" << endl;
else
{
Node* newTop = new Node;
if(top1 == NULL)
{
newTop->data = input;
newTop->next = NULL;
top1 = newTop;
count++;
}
else
{
newTop->data = input;
newTop->next = NULL;
top1 = newTop;
count++;
}
}
}
void print()
{
Node* n = new Node;
n = top1;
while( n != NULL)
{
cout << n->data << " , ";
n = n->next;
}
}
bool empty();
void top();
};
int main()
{
Stack* calcStack = new Stack(5);
calcStack->push(5);
calcStack->push(6);
calcStack->push(7);
calcStack->push(8);
calcStack->pop();
calcStack->print();
return 0;
}