-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueSLinked.java
More file actions
62 lines (48 loc) · 1.27 KB
/
Copy pathQueueSLinked.java
File metadata and controls
62 lines (48 loc) · 1.27 KB
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
package Queue;
import NodeList.SLNode;
public class QueueSLinked implements Queue{
private SLNode front;
private SLNode rear;
private int size;
public QueueSLinked() {
front=new SLNode();
rear=front;
size=0;
}
@Override
public int getSize() {
// TODO Auto-generated method stub
return size;
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return size==0;
}
@Override
public void enqueue(Object e) {
// TODO Auto-generated method stub
SLNode p=new SLNode(e,null);
rear.setNext(p);
rear=p;
size++;
}
@Override
public Object dequeue() throws QueueEmptyException {
// TODO Auto-generated method stub
if(size<1)
throw new QueueEmptyException("错误,空队列");
SLNode p=front.getNext();
front.setNext(p.getNext());
size--;
if(size<1) rear=front;
return p.getData();
}
@Override
public Object peek() throws QueueEmptyException {
// TODO Auto-generated method stub
if(size<1)
throw new QueueEmptyException("错误,空队列");
return front.getNext().getData();
}
}