sb는 작은따옴표와 큰따옴표의 사용을 구별하지 않아도 됐지만 System.out에 직접적으로 출력 데이터들을 붙일 때는 큰따옴표와 작은따옴표를 구별해서 사용해야 함을 알았음. 작은따옴표를 사용하니까 이상한 값이 나왔음.
package DataStructure;
import java.util.Scanner;
public class DS_Queue {
static final int MAX_N = 100;
static int front;
static int rear;
static int queue[] = new int[MAX_N];
static void queueInit() {
front = 0;
rear = 0;
}
static boolean queueIsEmpty() {
return (front == rear);
}
static boolean queueIsFull() {
if((rear + 1) % MAX_N == front)
return true;
else
return false;
}
static boolean queueEnqueue(int value) {
if(queueIsFull()) {
System.out.print("queue is full !");
return false;
}
queue[rear] = value;
rear++;
if(rear == MAX_N)
rear = 0;
return true;
}
static Integer queueDequeue() {
if(queueIsEmpty()) {
System.out.print("queue is empty !");
return null;
}
Integer value = new Integer(queue[front]);
front++;
if(front == MAX_N)
front = 0;
return value;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for(int t = 1; t <= T; t++) {
int N = sc.nextInt();
queueInit();
for(int n = 0; n < N; n++) {
int value = sc.nextInt();
queueEnqueue(value);
}
System.out.print("#" + t + " ");
while(!queueIsEmpty()) {
Integer value = queueDequeue();
if(value != null)
System.out.print(value.intValue() + " ");
}
System.out.println();
}
sc.close();
}
}
'SSAFY > Data Structure' 카테고리의 다른 글
Tree (0) | 2023.05.06 |
---|---|
Hash (0) | 2023.05.06 |
PriorityQueue (1) | 2023.05.06 |
Stack (0) | 2023.05.05 |