-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.cpp
More file actions
56 lines (49 loc) · 849 Bytes
/
stack.cpp
File metadata and controls
56 lines (49 loc) · 849 Bytes
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
#include <iostream>
#include <stdlib.h>
using namespace std;
//using automatic array
class stack
{
private:
//DATAMEMBERS
char data[10]; // automatic
int top_;
public:
stack(); //constructor
//member functions
int empty()
{
return (top_ == -1);
}
void push(char x)
{
data[++top_] = x;
}
void pop()
{
--top_;
}
char top()
{
return data[top_];
}
};
stack::stack() : top_(-1)
{ //init list
cout << "stack::stack() called" << endl;
}
int main()
{
char str[10] = "ABCDE";
stack s; //init by stack::stack():top(-1) call
for (int i = 0; i < 5; ++i)
{
s.push(str[i]);
}
while (!s.empty())
{
cout << s.top();
s.pop();
}
return 0;
}