-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueLarge.java
More file actions
54 lines (47 loc) · 1.09 KB
/
QueueLarge.java
File metadata and controls
54 lines (47 loc) · 1.09 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
public class QueueLarge {
class Node{
int data;
Node next;
Node(int data){
this.data=data;
this.next=null;
}
}
Node front,rear=null;
Node front2,rear2=null;
void enq(int data){
Node newnode=new Node(data);
if(rear==null){
front=rear=newnode;
return;
}
rear.next=newnode;
rear=newnode;
Node newnode2=new Node(data);
if(rear2==null||data>front2.data){
rear2.next=newnode2;
rear2=newnode;
}
}
void deq(){
if(front2==null){
System.out.println("empty");
return;
}
System.out.println("removed"+" "+front.data);
front=front.next;
if(front2.data==front.data){
front2=front2.next;
}
}
int max(){
if(front2==null){
System.out.println("empty");
return -1;
}
return front2.data;
}
public static void main(String[]args){
QueueLarge q=new QueueLarge();
}
}