스택 소스코드: Difference between revisions

From IT Wiki
(새 문서: == Java == <syntaxhighlight lang='java' line='line'> public class Stack { private int MAX = 5; private int top; private int[] item; public Stack() { top = 0; item = new in...)
 
No edit summary
 
(2 intermediate revisions by one other user not shown)
Line 41: Line 41:
== 출처 ==
== 출처 ==
[http://raisonde.tistory.com/entry/금융권-전산직-기출-문제-서술식 지식잡식 블로그]
[http://raisonde.tistory.com/entry/금융권-전산직-기출-문제-서술식 지식잡식 블로그]
[[분류:자료 구조]]
[[분류:알고리즘]]

Latest revision as of 00:50, 9 May 2019

Java[edit | edit source]

public class Stack {
	
	private int MAX = 5;
	private int top;
	private int[] item;
	
	public Stack() {
		top = 0;
		item = new int[MAX];
	}
	
	public void push(int num) {
		if(top >= item.length) {
			System.out.println("Stack is fulled");
			return ;
		} else {
			item[top] = num;			
			top = top + 1;
			
			System.out.println(num);
		}
	}
	
	public void pop() {
		if(top == 0) {
			System.out.println("Stack is empty");
		} else {
			top = top - 1;			
			int num;
			num = item[top];
			item[top] = 0;
			
			System.out.println(num);
		}
	}
}

출처[edit | edit source]

지식잡식 블로그