-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queue.java
74 lines (72 loc) · 1.57 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
66
67
68
69
70
71
72
73
74
package com.company;
public class Queue {
Node root = new Node();
Node last = new Node();
public Queue(){
root.data=null;
root.next=null;
last=root;
}
public void enqueue(int icData){
if (root.data==null){
root.data=icData;
last=root;
}
else {
Node yeni = new Node();
yeni.data=icData;
yeni.next=null;
last.next=yeni;
last=yeni;
}
}
public int dequeue(){
if (root.data==null){
System.out.println("Kuyruk Zaten Boş!");
return -1;
}
else if (root.next==null){
Node temp = root;
root.data=null;
return temp.data;
}
else {
Node temp = root;
root = root.next;
return temp.data;
}
}
public int front(){
if (root.data==null){
System.out.println("Kuyruk Boş");
return -1;
}
else {
return root.data;
}
}
public int size(){
if (root.data == null) {
return 0;
} else if (root.next == null) {
return 1;
}
else {
Node iter = root;
int i = 0;
while (iter.next!=null){
iter=iter.next;
i++;
}
return i+1;
}
}
public boolean isEmpty(){
if (root.data==null){
return true;
}
else {
return false;
}
}
}