#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
typedef int Element;
typedef struct {
Element data;
Node* link;
}Node;
Node* top = NULL;
void error(const char str[]) {
printf("%s\n", str);
exit(1);
}
void init_stak() { top = NULL; }
int is_empty() { return top == NULL; }
int size() {
Node* p;
int count = 0;
for (p = top; p != NULL; p = p->link) {
count++;
}
return count;
}
void push(Element e) {
Node* p = (Node*)malloc(sizeof(Node));
p->data = e;
p->link = top;
top = p;
}
Element pop() {
Node* p;
Element e;
if (is_empty() == 1) error("스택 공백 에러");
p = top;
e = p->data;
top = p->link;
free(p);
return e;
}
Element peek() {
if (is_empty() == 1) error("스택 공백 에러");
return top->data;;
}
void destroy_stack() {
while (is_empty() == 0) pop();
}
int main()
{
init_stak();
return 0;
}