-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack.cpp
More file actions
80 lines (67 loc) · 1.19 KB
/
Copy pathStack.cpp
File metadata and controls
80 lines (67 loc) · 1.19 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
80
#include"Stack.h"
#include<stdio.h>
void CreateStack(Stack *ps){
ps->top = 0;
}
void push(StackEntry e, Stack *ps){
ps->entry[ps->top] = e;
ps->top++;
}
int StackFull(Stack *ps)
{
if(ps->top == MAXSTACK)
return 1;
else
return 0;
}
void pop(StackEntry *pe, Stack *ps){
ps->top--;
*pe = ps->entry[ps->top];
}
int StackEmpty(Stack *ps){
if(ps->top == 0)
return 1;
else
return 0;
}
void StackTop(StackEntry *pe, Stack *ps){
*pe = ps->entry[ps->top];
}
int StackSize(Stack *ps){
return ps->top;
}
void ClearStack(Stack *ps){
ps->top = 0;
}
void TraverseStack(Stack *ps,void (*pf)(StackEntry)){
for(int i=ps->top; i>0; i--)
{
(*pf)(ps->entry[i-1]);
}
}
void MakeStack0(Stack *sp)
{
for(int i = 0; i<sp->top; i++)
sp->entry[i] = 0;
}
StackEntry FirstElement(Stack *ps)
{
return ps->entry[0];
}
void CopyStack(Stack *src,Stack *dest)
{
for(int i=0; i<src->top; i++){
dest->entry[i] = src->entry[i];
}
dest->top = src->top;
}
StackEntry RemoveFirstElement(Stack *ps)
{
StackEntry temp = ps->entry[0];
int i;
for(i = 1; i<MAXSTACK; i++){
ps->entry[i-1] = ps->entry[i];
}
ps->top--;
return temp;
}