Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4da8aa5

Browse files
Create Stack.c
1 parent d05ac48 commit 4da8aa5

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎Stack.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#define _CRT_SECURE_NO_WARNINGS
2+
#include <stdio.h>
3+
#define MAX 10
4+
5+
// stack 구조체
6+
typedef struct {
7+
int container[MAX];
8+
int top;
9+
} stack;
10+
11+
// stack을 만들고 top을 -1로 초기화 한후 반환
12+
stack getNewStack() {
13+
stack stack1;
14+
stack1.top = -1;
15+
return stack1;
16+
};
17+
18+
// stack에 value를 push
19+
void push(stack* sptr, int value) {
20+
sptr->container[++sptr->top] = value;
21+
}
22+
23+
// stack에서 pop
24+
int pop(stack* sptr) {
25+
return sptr->container[sptr->top--];
26+
}
27+
28+
int main(void) {
29+
stack st1 = getNewStack();
30+
31+
for (int i = 0; i < 10; i++) {
32+
push(&st1, i);
33+
printf("push : %d\n", i);
34+
}
35+
36+
for (int i = 0; i < 10; i++)
37+
printf("pop : %d\n", pop(&st1));
38+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /