-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC++stack.cpp
More file actions
63 lines (63 loc) · 955 Bytes
/
C++stack.cpp
File metadata and controls
63 lines (63 loc) · 955 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
57
58
59
60
61
62
63
#include<iostream>
using namespace std;
class Stack
{
private:
int data_count;
int *member_stack;
int stack_sum;
public:
void Stack_Creat(int n)
{
member_stack=(int*)malloc(n*sizeof(int));
data_count=-1;
stack_sum=n-1;
}
bool IsFull()
{
if(data_count==stack_sum)
return true;
else
return false;
}
void Stack_Add(int item)
{
if(IsFull())
return;
else
member_stack[++data_count]=item;
}
bool IsEmpty()
{
if(data_count==-1)
return true;
else
return false;
}
void Stack_delete()
{
if(IsEmpty())
return;
else
{
cout<<member_stack[data_count--]<<endl;
}
}
};
int main()
{
Stack test_stack;
int value,test_data=0;
cin>>value;
test_stack.Stack_Creat(value);
for(;test_data<value;test_data++)
{
test_stack.Stack_Add(test_data+1);
}
test_data--;
for(;test_data>=0;test_data--)
{
test_stack.Stack_delete();
}
return 0;
}