-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueueArray.java
More file actions
86 lines (71 loc) · 1.83 KB
/
QueueArray.java
File metadata and controls
86 lines (71 loc) · 1.83 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.util.ArrayList;
import MyQueue.Node;
public class QueueArray<E>{
// Sollte die Implementierung duch die Inneren Klasse erfolgt werden (sihe ganz Unten)
ArrayList list;
private Object head;
//default constructor for creating an empty queue
public Queue? (){ //? is a wildcard for second part of classname
list = new ArrayList();
}
//inserts item at the end of the queue
//https://stackoverflow.com/questions/33185505/add-items-to-the-end-of-a-queue
public <E> void enqueue(MyIterator<E> head,E item) {
MyIterator<E> last = head;
while (last.next != null) {
last = (MyIterator<E>) last.next;
}
last.next = new Queue?<E> (item, null);
}
//returns the head of the queue and deletes it from the queue;
//returns null if queue is empty
public E dequeue() {
if(head==null){
return null;
}else{
Node help = head;
head = head.next;
return help.data;
}
}
//returns the number of elements in the queue
public int size() {
return list.size();
}
//test if queue is empty
public boolean isEmpty() {
list.isEmpty();
}
//returns a String-representation of this queue as
//[item1, item2, ..., itemn] with item1 as the top item
//and itemn as the last inserted item
// ???????
public String toString () {
String out="";
for(int i=0;i<list.size();i++){
if(list.get(i)!=null){
if(i==list.size()-1){
out = out + list.get(i);
break;
}
out = out + list.get(i)+", ";
}
}
return "["+out+"]";
}
//returns an iterator for traversing the queue
public MyIterator<E> getIterator(){
}
private class MyIteratorX<E> implements MyIterator<E>{
@Override
public boolean hasNextint(int objectInBox) {
// TODO Auto-generated method stub
return false;
}
@Override
public E getNext() {
// TODO Auto-generated method stub
return null;
}
}
}