-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.java
65 lines (54 loc) · 1.5 KB
/
Queue.java
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
package com.example.chris.studygroup;
/**
* Created by Chris on 11/14/2016.
*/
public class Queue {
Node header,start,current;
Queue(int length){
header= new Node(null);
start=header;
current=header;
for(int x=0;x<length-1;x++) {
Node temp= new Node(null);
current.setNext(temp);
current = current.getNext();
}
current.setNext(header);
}
public void push(GenData data){
current= start;
while(current.getData()!=null&¤t.getNext()!=start){
current=current.getNext();
}
if(current.getData()!=null){
start.setData(data);
start=start.getNext();
}else current.setData(data);
}
public GenData pop(){
GenData temp;
current=start;
start=current.getNext();
temp =current.getData();
current.setData(null);
return temp;
}
private GenData[] toArr(){
GenData[] ret;
current=start;
return null;
}
public String toString(){
String ret = " ";
current=start;
while(current.getData()!=null&¤t.getNext()!=start){
ret+=current.getData().toString();
current=current.getNext();
}
if(current.getData()!=null) {
ret += current.getData().toString();
current = current.getNext();
}
return ret;
}
}