-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayStack.cpp
More file actions
53 lines (42 loc) · 998 Bytes
/
ArrayStack.cpp
File metadata and controls
53 lines (42 loc) · 998 Bytes
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
#include "ArrayStack.h"
void AS_CreateStack(ArrayStack** Stack, int Capacity)
{
/* 스택을 자유 저장소에 생성 */
(*Stack) = (ArrayStack*)malloc(sizeof(ArrayStack));
/* 입력된 Capacity만큼의 노드를 자유 저장소에 생성 */
(*Stack)->Nodes = (Node*)malloc(sizeof(Node)*Capacity);
/* Capacity 및 Top 초기화 */
(*Stack)->Capacity = Capacity;
(*Stack)->Top = 0;
}
void AS_DestroyStack(ArrayStack* Stack)
{
/* 노드를 자유저장소에서 해제 */
free(Stack->Nodes);
/* 스택을 자유저장소에서 해제 */
free(Stack);
}
void AS_Push(ArrayStack* Stack, ElementType Data)
{
int Position = Stack->Top;
Stack->Nodes[Position].Data = Data;
Stack->Top++;
}
ElementType AS_Pop(ArrayStack* Stack)
{
int Position = --(Stack->Top);
return Stack->Nodes[Position].Data;
}
ElementType AS_Top(ArrayStack* Stack)
{
int Position = Stack->Top - 1;
return Stack->Nodes[Position].Data;
}
int AS_GetSize(ArrayStack* Stack)
{
return Stack->Top;
}
int AS_IsEmpty(ArrayStack* Stack)
{
return (Stack->Top == 0);
}