-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
72 lines (53 loc) · 1.31 KB
/
stack.cpp
File metadata and controls
72 lines (53 loc) · 1.31 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
// Class automatically generated by Dev-C++ New Class wizard
#include "stack.h" // class's header file
#include "link.h"
#include <iostream>
using namespace std;
// class constructor
Stack::Stack()
{ size = 0;
// insert your code here
}
// class destructor
Stack::~Stack()
{
// insert your code here
}
//FUNCTION DEFFINITION
void Stack::Push(char num)
{ Link * link;
link = new Link;
link -> value = num;
if (size > 0)
{ link -> prev = top;
top = link;
size ++;
}
else if (size == 0)
{ top = link;
size ++;
}
} // add to the stack
char Stack::pop()
{ if (size >1)
{
char temp;
temp = top -> value;
top = top -> prev;
size = size -1;
return temp;
}
if (size ==1)
{char temp;
temp = top -> value;
//top = null;
size = size -1;
return temp;
}
if (size <=0)
{cout<<"I am sorry, you cannot do that." <<endl;
}
} //remove the last link frm the stack
char Stack::peak()
{ return top->value;
} // looks at top of stack without removing it.