-
Notifications
You must be signed in to change notification settings - Fork 0
/
Implement stack with static arrays.cpp
79 lines (75 loc) · 1.59 KB
/
Implement stack with static arrays.cpp
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
//============================================================================
/*
* in this file i implement the stack using array
* note that the stack size here i defined it as a 1001
* and if it exceed 1000 element it will considered a stack over flow ;
*
* */
// Name : Implement.cpp
// Author : mohand sakr;
// Version :1
// Copyright : use this code under your responsibility ;
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
void ShowTheTop();
void Push();
void Pop();
bool isempty();
int Stack[1001];
int top=0;
int main() {
int choice;
do{
cout<<"welcome\n"<<"this is the stack implementation program please inser a choice \n ";
cout<<"To Push insert 1\n";
cout<<"To pop insert 2\n";
cout<<"To see the element in the top of the stack insert 3\n";
cout<<"To exit insert 0 \n";
cin>>choice;
if(choice==1){
Push();
}
else if(choice==2){
Pop();
}
else if(choice==3){
ShowTheTop();
}
}
while(choice);
return 0;
}
bool isempty(){
if(!top){
return 1;
}
else
return 0;
}
void ShowTheTop(){
if(isempty()){
cout<<"the stack is empty \n";
}
else{
cout<<"the element on the top \n"<<Stack[top]<<"\n";}
};
void Push(){
if(top==1001){
cout<<"the Stack is Full and this is a stack overflow ";
}
else{
cout<<"enter a value \n";
top+=1;
cin>>Stack[top];}
}
void Pop(){
if(isempty())
cout<<"the stack is empty this is a under folow error\n ";
else{
top-=1;
cout<<"poping successfuly\n";
cout<<"top :"<<top<<"\n";
}
}