GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — DateStructure/CircleQueueTest.java at main · xcdh127/DateStructure

Expand file tree

/

CircleQueueTest.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
98 lines (84 loc) · 2.39 KB
/

CircleQueueTest.java

Copy path

File metadata and controls

98 lines (84 loc) · 2.39 KB
Raw
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package CircleQueue;
import com.sun.jmx.remote.internal.ArrayQueue;
/**
* @program: DataStructure
* @description: 环形队列
* @author: Mr.Sun
* @create: 2021-06-10 22:23
**/
public class CircleQueueTest {
public static void main(String[] args) {
CircleQueue queue = new CircleQueue(3 );
queue.add(3);
queue.add(2);
queue.getQueue();
queue.getQueue();
queue.add(6);
queue.add(7);
// queue.getQueue();//取出队列的一个元素
// System.out.println(queue.getHead());//输出队列的第一个元素
System.out.println("****");
queue.show();
}
}
class CircleQueue{
private int maxSize;
private int rear ;
private int head ;
private int[] arr ;
// 初始化队列的大小
public CircleQueue(int maxSize){
this.maxSize = maxSize;
rear = 0;
head = 0;
arr = new int[maxSize];
}
// 判断队列为空
public boolean isEmpty(){
return rear == head;
}
// 判断队列已满
public boolean isFull(){
return (rear+1)%maxSize==head ;
}
// 向队列添加元素
public void add(int n){
if (isFull()){
throw new RuntimeException("队列已满,不能添加");
}
arr[rear] = n;
rear = (rear+1)%maxSize;
}
// 显示队列头的值
public int getHead(){
if (isEmpty()){
throw new RuntimeException("队列为空,不能获取队头元素");
}
return arr[head];
}
// 显示队列所有的元素
public void show(){
if (isEmpty()){
throw new RuntimeException("队列为空,不能展示");
}
for (int i =head;i< head+getNum();i++){
System.out.println(arr[i%maxSize]);
}
}
// 获取队列中有效数据的个数
public int getNum(){
if (isEmpty()){
throw new RuntimeException("队列为空,不能获取个数");
}
return (rear+maxSize-head)%maxSize;
}
// 取出队列的头元素
public int getQueue(){
if (isEmpty()){
throw new RuntimeException("队列为空,不可取");
}
int value = arr[head];
head = (head+1)%maxSize;
return value ;
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.