-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathProblem-1.java
62 lines (41 loc) · 1.08 KB
/
Problem-1.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
/**
* @author AkashGoyal
*/
/**
--------------------- Problem----------->> Implement Queue using Linked List
Problem Link :- https://practice.geeksforgeeks.org/problems/implement-queue-using-linked-list/1
Reference:- https://www.geeksforgeeks.org/queue-set-1introduction-and-array-implementation/
*/
class MyQueue
{
QueueNode front, rear;
//Function to push an element into the queue.
void push(int a)
{
QueueNode node=new QueueNode(a);
if(rear!=null)
{
rear.next=node;
rear=rear.next;
}
else
{
front=rear=node;
}
}
//Function to pop front element from the queue.
int pop()
{
if(front==null)
{
return -1;
}
int data=front.data;
front=front.next;
if(front==null)
{
rear=null;
}
return data;
}
}