Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
59 lines (50 loc) · 1.69 KB

File metadata and controls

59 lines (50 loc) · 1.69 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package ch09;
import java.util.Arrays;
public class P25_1 {
int[] q;
int front = 0, rear = -1, len = 0;
public P25_1(int k) {
// k 크기의 원형 큐로 사용할 배열 선언
this.q = new int[k];
}
public boolean enQueue(int value) {
// 꽉 차 있지 않다면 삽입 진행
if (!this.isFull()) {
// rear 포인터 한 칸 앞으로 이동, 최대 크기를 초과하면 나머지 위치로 이동
this.rear = (this.rear + 1) % this.q.length;
// rear 위치에 값 삽입
this.q[rear] = value;
// 현재 큐의 크기 계산
this.len++;
return true;
} else
return false;
}
public boolean deQueue() {
// 텅 비어 있지 않다면 삭제 진행
if (!this.isEmpty()) {
// front 포인터 한 칸 앞으로 이동, 최대 크기를 초과하면 나머지 위치로 이동
this.front = (this.front + 1) % this.q.length;
// 현재 큐의 크기 계산
this.len--;
return true;
} else
return false;
}
public int Front() {
// 맨 앞의 값을 가져온다.
return (this.isEmpty()) ? -1 : this.q[this.front];
}
public int Rear() {
// 맨 뒤의 값을 가져온다.
return (this.isEmpty() ? -1 : this.q[this.rear]);
}
public boolean isEmpty() {
// 현재 큐의 크기가 0이면 비어 있음
return this.len == 0;
}
public boolean isFull() {
// 현재 큐의 크기가 전체 큐의 크기와 일치하면 꽉 차 있음
return this.len == this.q.length;
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.