-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.cpp
More file actions
79 lines (76 loc) · 1.04 KB
/
stack.cpp
File metadata and controls
79 lines (76 loc) · 1.04 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
73
74
75
76
77
78
79
#include<iostream>
using namespace std;
struct stack
{
int top,bottom,capacity,size;
int* arr;
};
typedef struct stack sun;
sun* create(int cap)
{
sun* s=new stack;
s->capacity=cap;
s->top=s->bottom=-1;
s->size=0;
s->arr=new int[s->capacity];
return s;
}
bool isempty(sun* s)
{
if(s->size==0)
return true;
else
return false;
}
bool isfull(sun* s)
{
if(s->size==s->capacity)
return true;
else
return false;
}
sun* push(sun* s,int item)
{
if(isfull(s))
cout<<"\nSorry-stack is full ";
else
{
(s->top)++;
s->arr[s->top]=item;
s->bottom=0;
(s->size)++;
return s;
}
}
void pop(sun* s)
{
if(isempty(s))
cout<<"\nSorry-stack is empty ";
else
{
(s->top)--;
(s->size)--;
}
}
void trav(sun* s)
{
if(isempty(s))
cout<<"\nNothing to show.it's empty ";
else
{
for(int i=s->bottom;i<s->size;i++)
cout<<s->arr[i]<<" ";
cout<<"\n";
}
}
int main()
{
sun* s=new stack;
s=create(10);
for(int i=0;i<7;i++)
s=push(s,i);
cout<<"\n";
trav(s);
pop(s);
trav(s);
}