-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueue1.java
More file actions
59 lines (59 loc) · 1.07 KB
/
Queue1.java
File metadata and controls
59 lines (59 loc) · 1.07 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
public class Queue1
{
static Node front;
static Node back;
static class Node
{
int data;
Node next;
Node(int d)
{
data = d;
next = null;
}
}
public static void push(int d)
{
Node n = new Node(d);
if(front==null)
{
front = n;
back = front;
return;
}
back.next = n;
back = n;
}
public static void pop()
{
if(front == null)
{
System.out.println("empty");
return;
}
else
{
front = front.next;
}
}
public static void display(Queue1 q)
{
Node temp = front;
while(temp!=null)
{
System.out.print(temp.data+" ");
temp = temp.next;
}
}
public static void main(String[] args)
{
Queue1 q = new Queue1();
push(10);
push(20);
push(30);
display(q);
System.out.println();
pop();
display(q);
}
}