-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestQueue.java
More file actions
64 lines (57 loc) · 1.47 KB
/
RequestQueue.java
File metadata and controls
64 lines (57 loc) · 1.47 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
import Includes.*;
public class RequestQueue {
private Node<RequestData> front;
private Node<RequestData> back;
private int length = 0;
public RequestData getFront() {
return this.front.data;
}
public int getLength() {
/*
* Your code here.
*/
return this.length;
}
public void push(int ISBN, int UserID) {
/*
* Your code here.
*/
// new element of data type RequestData is created
RequestData rd =new RequestData();
rd.ISBN = ISBN;
rd.UserID = UserID;
Node<RequestData> elem = new Node<>();
elem.data = rd;
// adding this element
if (front == null){
front = elem;
back = front;
}
else {
elem.previous=back;
back.next=elem;
back = elem;
}
this.length ++;
return;
}
public void pop() { // processing needs to be done before popping,
/*
* Your code here.
*/
if(front!=null){
front=front.next;
this.length --;
}
return;
}
public String toString(){
Node<RequestData> temp = front;
String s = "Length: " + length + "\n";
while(temp != null){
s+=temp.data.toString();// temp.data gives data type of RequestData and uses its toString method
temp = temp.next; // .next is method of Node
}
return s;// returns a string containing length and data in queue
}
}