Skip to content

Added code for Queue using LL #190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions QueueLLDriver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class QueueLLDriver{
public static void main(String[] args){
QueueUsingLL q = new QueueUsingLL();
q.isEmpty();
q.enqueue(13);
q.enqueue(21);
q.enqueue(34);
q.enqueue(62);
q.dequeue();
q.dequeue();
}
}
39 changes: 39 additions & 0 deletions QueueUsingLL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
class QueueUsingLL{
private class Node{
int data;
Node next;
}
Node front,rear;

boolean isEmpty(){
if(front == null && rear == null){
return true;
}
else{
return false;
}
}
void enqueue(int key){
Node temp = new Node();
temp.data = key;
temp.next = null;
if(front == null && rear == null){
front = rear = temp;
}
else{
rear.next = temp;
rear = temp;
}
}
void dequeue(){
if(isEmpty()){
System.out.println("Queue is empty");
}
else if(front == rear){
front = rear = null;
}
else{
front = front.next;
}
}
}