Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- call by value
- 회귀학습
- Nonlinear Function
- regression
- inheritance
- MapReduce
- Overloading
- 머신러닝
- virtual function
- 비선형모델
- Class
- call by reference
- 최소제곱법
- least square
- 딥러닝
- 선형모델
- 비선형 함수
- c++
- overriding
- struct
- Nonlinear Model
- 맵리듀스
- 지도학습
- local minimum
- member function
- Machine learning
- kubernetes
- Effective C++
- 회귀
- Linear Regression
Archives
- Today
- Total
J's Study log
[Data Structure] basic idea of Stack 본문
Stack

Stack in data structure literally means stacking data in memory following 'LIFO method'.
Top
As the picture shows, same size of data is structed in one way and to access the data you can access data from 'top'.
('top' points the last data input)
Data in
Operators
Input new data with operator 'push'.
Extract data and return with operator 'pop'.
And there's also 'peek' operator which returns the last input character, without extracting it.
In abstract data type, stack is declared like this.
#include <stdio.h> #include <stdlib.h> #define MaxStackSize 100 typedef int element; element stack[MaxStackSize]; int top = -1; // Check if stack is empty int isEmpty() { return(top == -1 ? 1 : 0); } // Check if stack is full int isFull() { return (top == (MaxStackSize - 1)); } // Input new data in stack void push(element item) { if(isFull() == 1) { printf("stack is full.\n"); } else { stack[++top] = item; } } // Extract data from stack and returns element pop() { if (isEmpty() == 1) { printf("Stack is empty.\n"); } else { printf("%c\n",stack[top]); return stack[top--]; } } // Return 'top' data. element peek() { if(is_empty()){ fprintf(stderr, "stack is empty."); exit(1); } else return stack[top]; } int main () { push('A'); push('B'); push('C'); push('D'); push('E'); printf("isFull : %d\n", isFull()); pop(); pop(); pop(); pop(); pop(); printf("isEmpty : %d", isEmpty()); return 0; }