public class StackPractice {
public static void main(String args[]){
Stack<Integer> stack = new Stack<>();
stack.push(1);
stack.push(2);
stack.push(3);
stack.push(4);
stack.push(5);
stack.push(6);
stack.push(7);
stack.push(8);
stack.pop();
stack.pop();
while (!stack.isEmpty()){
System.out.println(stack.peek());
stack.pop();
}
}
}
push, pop
while(!stack.isEmpty)
public class QueuePractice {
public static void main(String args[]){
Queue<Integer> q = new LinkedList<>();
q.offer(5);
q.offer(3);
q.offer(4);
q.poll();
while(!q.isEmpty()){
System.out.println(q.poll());
}
}
}
add, offer -> 오류때 차이
public class RecursePractice {
public static void main(String[] args) {
recurse(10);
}
static void recurse(int i){
if(i<0) return ;
System.out.println(i + "번째");
recurse(i-1);
}
}
A와B의 최대공약수는 A%B = R (A>B), B와 R의 최대공약수와 같다.
--> Recursion 가능