#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define EMPTY 0
int A;
struct node {
int data;
struct node * link;
};
typedef struct node Stack;
Stack * get_node() {
Stack * tmp;
tmp = (Stack *)malloc(sizeof(Stack));
tmp->link = EMPTY;
return tmp;
}
void push(Stack **top, int data) {
Stack *tmp;
tmp = *top;
*top = get_node();
(*top)->> (*top)->link = tmp;
}
int pop(Stack **top) {
Stack *tmp;
int A;
tmp = *top;
*top = tmp->link;
A = tmp->data;
free(tmp);
return A;
}
void PRINT(Stack **top) {
Stack *aaa = EMPTY;
aaa = *top;
if (aaa == NULL)
return;
printf("%d\n", aaa->data);
aaa = aaa->link;
PRINT(&aaa);
}
void END(Stack **top) {
Stack * aaa = EMPTY;
aaa = *top;
while (aaa != NULL) {
printf("%d\n", pop(&aaa));
Sleep(1000);
}
}
void main() {
Stack * top = EMPTY;
int option;
int ram;
Stack * aaa = EMPTY;
while (1) {
printf("stack 프로그램 입니다.\n");
printf("1. push\n");
printf("2. pop\n");
printf("3. print_data\n");
printf("4. 종료\n");
printf(">>>>>>> : ");
scanf_s("%d", &option);
switch (option) {
case 1:
printf("데이터 입력 : ");
scanf_s("%d", &ram);
push(&top, ram);
break;
case 2:
printf("%d\n", pop(&top));
system("pause");
break;
case 3:
PRINT(&top);
printf("empty data");
system("pause");
break;
case 4:
printf("모든 data 공간 해제후 종료\n");
Sleep(1000);
END(&top);
printf("empty data\n");
exit(1);
}
system("cls");
}
}
이런 코드에서
빨간부분이요..
왜 저런 구조체 선언하는지
그니깐 저게 왜 필요한지 뭘 의미하는지 궁금해요 ㅜㅜ
댓글 0