-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempStack.cpp
More file actions
64 lines (56 loc) · 1.12 KB
/
tempStack.cpp
File metadata and controls
64 lines (56 loc) · 1.12 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
#include<iostream>
#include<windows.h>
using namespace std;
template<typename t1>
t1 *every;
struct arrayStack{
int top, capacity,*array;
};
struct arrayStack *createStack(int cap){
struct arrayStack *stack;
stack=(struct arrayStack*)malloc(sizeof(struct arrayStack));
stack->top=-1;
stack->capacity=cap;
stack->array=(int*)malloc(sizeof(int)*stack->capacity);
}
int isFull(struct arrayStack *stack){
if(stack->top==stack->capacity-1){
return 1;
}
return 0;
}
int isEmpty(struct arrayStack *stack){
if(stack->top==-1){
return 1;
}
return 0;
}
void push(struct arrayStack *stack, int item){
if(!isFull(stack)){
stack->top++;
stack->array[stack->top]=item;
}
else{
cout<<"Stack is FUll";
system("pause");
}
}
int pop(struct arrayStack *stack){
int temp;
if(!isEmpty(stack)){
temp=stack->array[stack->top];
stack->top--;
return temp;
}
else{
cout<<"The stack is empty:";
system("pause");
}
}
main(){
struct arrayStack *stack;
stack=createStack(1);
pop(stack);
push(stack,45);
cout<<pop(stack);
}