-
Notifications
You must be signed in to change notification settings - Fork 0
/
스택의 활용.c
61 lines (54 loc) · 901 Bytes
/
스택의 활용.c
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
#include <stdio.h>
#include <stdlib.h>
#include<stdbool.h>
#define STACK_SIZE 20
typedef char element;
typedef struct {
element data[STACK_SIZE];
int top;
}Stack;
Stack s;
void initStack( Stack *s );
bool
isFull();
bool
isEmpty();
void push( element data );
element pop();
int main(){
int i;
char str[20];
printf("문자열 입력 : ");
scanf("%s", str);
initStack(&s);
for(i=0;str[i]!='\0';i++) {
push(str[i]);
}
while(!isEmpty()) {
printf("%c", pop());
}
return 0;
}
void initStack( Stack *s ){
s->top=-1;
}
bool isFull(){
return s.top==STACK_SIZE-1;
}
bool isEmpty(){
return s.top==-1;
}
void push( element c ){
if(isFull()) {
printf("stack is full\n");
return;
}
s.data[++(s.top)]=c;
}
element pop(){
if(isEmpty()) {
printf("stack is empty\n");
return 0;
}
return s.data[(s.top)--];
}