-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueue.java
59 lines (46 loc) · 1.01 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
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Queue
{
ArrayList<Integer> line = new ArrayList<Integer>(1);
int left;
int right;
int head;
Queue()
{
head=0;
right=0;
left=0;
}
public void insert(int val)
{
line.add(left,val);
right++;
//System.out.println("Right: "+right+"\nLeft: "+left);
}
public void delete()
{
line.remove(--right);
//right--;
//System.out.println("Right: "+right+"\nLeft: "+left);
}
public void show()
{
System.out.println("Right: "+right+"\nLeft: "+left);
System.out.println(line);
}
public static void main (String[] args) throws java.lang.Exception
{
System.out.println("Queue using ArrayList");
Queue q1=new Queue();
q1.insert(5);
q1.insert(6);
q1.insert(7);
q1.show();
q1.delete();
q1.show();
}
}