โข
Stack Example
package com.collection.stack;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class Coin {
private int value;
}
Java
๋ณต์ฌ
package com.collection.stack;
import java.util.Stack;
public class StackExample {
public static void main(String[] args) {
Stack<Coin> coinBox = new Stack<>();
coinBox.push(new Coin(500));
coinBox.push(new Coin(100));
coinBox.push(new Coin(50));
coinBox.push(new Coin(10));
coinBox.push(new Coin(5));
coinBox.push(new Coin(1));
while (!coinBox.isEmpty()) {
Coin c = coinBox.pop();
System.out.println("๊บผ๋ธ ๋์ : " + c.getValue() + "์, " + coinBox.size() + "๊ฐ ๋จ์");
}
}
}
Java
๋ณต์ฌ
โข
Queue Example
package com.collection.queue;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public class Message {
private String command, to;
}
Java
๋ณต์ฌ
package com.collection.queue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.LinkedList;
import java.util.Queue;
public class QueueExample {
public static void main(String[] args) {
Queue<Message> msgQueue = new LinkedList<>();
msgQueue.offer(new Message("sendMail", "ํํด๋ฒ ๋ฆฌํผ"));
msgQueue.offer(new Message("Call", "ํ๋ก์ํ "));
msgQueue.offer(new Message("sendKakao", "E-sens"));
msgQueue.offer(new Message("CallDeny", "Uneducated Kids"));
while (!msgQueue.isEmpty()) {
Message msg = msgQueue.poll();
switch (msg.getCommand()) {
case "sendMail":
System.out.println(msg.getTo() + "์๊ฒ ๋ฉ์ผ์ ๋ณด๋
๋๋ค.");
break;
case "Call":
System.out.println(msg.getTo() + "์๊ฒ ์ ํํฉ๋๋ค.");
break;
case "sendKakao":
System.out.println(msg.getTo() + "์๊ฒ ์นดํกํฉ๋๋ค.");
break;
case "CallDeny":
System.out.println(msg.getTo() + "์๊ฒ ์ค๋ ์ ํ๋ ๋ฌด์ํฉ๋๋ค.");
break;
}
}
}
}
Java
๋ณต์ฌ




