Notice
Recent Posts
Recent Comments
Link
고양이 여름이의 지식채널
[Java] 큐(Queue) 코드 구현 본문
선입선출(FIFO, First in first out) 방식의 자료구조.
package QueueList;
import java.util.ArrayList;
import java.util.Scanner;
public class Queuetest {
Scanner sc = new Scanner(System.in);
ArrayList<String> al;
public Queuetest(){
al = new ArrayList<String>();
}
public int push(){
System.out.print(" 입력 : ");
al.add(sc.next());
return 1;
}
public int pop(){
al.remove(0);
return 1;
}
public int getFirst(){
System.out.println(al.get(0));
return 1;
}
public int listSize(){
for(int i = 0; i < al.size(); i++){
System.out.print(al.get(i));
}
return 1;
}
}
실행
package QueueList;
public class mainClass {
public static void main(String[] args) {
Queuetest cls = new Queuetest();
cls.push();
cls.push();
cls.push();
cls.listSize();
cls.getFirst();
cls.pop();
cls.listSize();
}
}
728x90
반응형
Comments