연결리스트로 Stack 구현하기 - c언어
·
Data structure
Stack이란? Stack이란 FILO(First - In - Last -Out)형태로 먼저입력된 값이 가장 나중에 출력되는 형태이다. 스택은 2가지 함수로 구현할수 있는데 push함수와 pop함수로 push함수는 값을 넣을때마다 Header에 노드를 붙히고, pop을할때는 Header에 붙어있는 노드부터 없애는 형태이다. 1. 연결리스트 구조체로 정의하기 typedef struct Node { int data; struct Node* next; }Node; Node* head; Node* tail; 2. 초기 Header 와 Tail 선언 및 할당 void init() { head = (Node*)malloc(sizeof(Node)); tail = (Node*)malloc(sizeof(Node)); h..