-
Notifications
You must be signed in to change notification settings - Fork 0
/
P83.java
59 lines (47 loc) · 903 Bytes
/
P83.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
import java.util.*;
import java.io.*;
// Using linkedList
class Node {
int val;
Node next = null;
Node(int val) {
this.val = val;
}
}
public class Queue {
Node head;
Node tail;
int s = 0;
Queue() {
}
/*----------------- Public Functions of Queue -----------------*/
boolean isEmpty() {
return s == 0;
}
void enqueue(int data) {
Node n = new Node(data);
if (head == null) {
head = n;
tail = n;
} else {
tail.next = n;
tail = tail.next;
}
s++;
}
int dequeue() {
if (s == 0)
return -1;
else {
int v = head.val;
head = head.next;
s--;
return v;
}
}
int front() {
if (s == 0)
return -1;
return head.val;
}
}