SlideShare a Scribd company logo
Using NetBeans
Implement a queue named QueueLL using a Linked List (same as we did for the stack). This
implementation must be used in all the following problems.
Implement a queue QueueST using a stack (use StackLL).
Test your implementations in the main with examples.
Solution
Answer:-
import java.util.*;
/* Class Node */
class Node
{
protected int data;
protected Node link;
/* Constructor */
public Node()
{
link = null;
data = 0;
}
/* Constructor */
public Node(int d,Node n)
{
data = d;
link = n;
}
/* Function to set link to next Node */
public void setLink(Node n)
{
link = n;
}
/* Function to set data to current Node */
public void setData(int d)
{
data = d;
}
/* Function to get link to next node */
public Node getLink()
{
return link;
}
/* Function to get data from current Node */
public int getData()
{
return data;
}
}
/* Class linkedQueue */
class linkedQueue
{
protected Node front, rear;
public int size;
/* Constructor */
public linkedQueue()
{
front = null;
rear = null;
size = 0;
}
/* Function to check if queue is empty */
public boolean isEmpty()
{
return front == null;
}
/* Function to get the size of the queue */
public int getSize()
{
return size;
}
/* Function to insert an element to the queue */
public void insert(int data)
{
Node nptr = new Node(data, null);
if (rear == null)
{
front = nptr;
rear = nptr;
}
else
{
rear.setLink(nptr);
rear = rear.getLink();
}
size++ ;
}
/* Function to remove front element from the queue */
public int remove()
{
if (isEmpty() )
throw new NoSuchElementException("Underflow Exception");
Node ptr = front;
front = ptr.getLink();
if (front == null)
rear = null;
size-- ;
return ptr.getData();
}
/* Function to check the front element of the queue */
public int peek()
{
if (isEmpty() )
throw new NoSuchElementException("Underflow Exception");
return front.getData();
}
/* Function to display the status of the queue */
public void display()
{
System.out.print(" Queue = ");
if (size == 0)
{
System.out.print("Empty ");
return ;
}
Node ptr = front;
while (ptr != rear.getLink() )
{
System.out.print(ptr.getData()+" ");
ptr = ptr.getLink();
}
System.out.println();
}
}
/* Class LinkedQueueImplement */
public class LinkedQueueImplement
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
/* Creating object of class linkedQueue */
linkedQueue lq = new linkedQueue();
/* Perform Queue Operations */
System.out.println("Linked Queue Test ");
char ch;
do
{
System.out.println(" Queue Operations");
System.out.println("1. insert");
System.out.println("2. remove");
System.out.println("3. peek");
System.out.println("4. check empty");
System.out.println("5. size");
int choice = scan.nextInt();
switch (choice)
{
case 1 :
System.out.println("Enter integer element to insert");
lq.insert( scan.nextInt() );
break;
case 2 :
try
{
System.out.println("Removed Element = "+ lq.remove());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 3 :
try
{
System.out.println("Peek Element = "+ lq.peek());
}
catch (Exception e)
{
System.out.println("Error : " + e.getMessage());
}
break;
case 4 :
System.out.println("Empty status = "+ lq.isEmpty());
break;
case 5 :
System.out.println("Size = "+ lq.getSize());
break;
default :
System.out.println("Wrong Entry  ");
break;
}
/* display queue */
lq.display();
System.out.println(" Do you want to continue (Type y or n)  ");
ch = scan.next().charAt(0);
} while (ch == 'Y'|| ch == 'y');
}
}
Ad

More Related Content

Similar to Using NetBeansImplement a queue named QueueLL using a Linked List .pdf (20)

1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
VictorXUQGloverl
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
The presention is about the queue data structure
The presention is about the queue data structureThe presention is about the queue data structure
The presention is about the queue data structure
gaurav77712
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
Ain-ul-Moiz Khawaja
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Sriram Raj
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
aromalcom
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
curwenmichaela
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Data Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptxData Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptx
RashidFaridChishti
 
public class Point {   Insert your name here    private dou.pdf
public class Point {    Insert your name here    private dou.pdfpublic class Point {    Insert your name here    private dou.pdf
public class Point {   Insert your name here    private dou.pdf
anandshingavi23
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
VictorXUQGloverl
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
The presention is about the queue data structure
The presention is about the queue data structureThe presention is about the queue data structure
The presention is about the queue data structure
gaurav77712
 
package singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdfpackage singlylinkedlist; public class Node { public String valu.pdf
package singlylinkedlist; public class Node { public String valu.pdf
amazing2001
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
in this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdfin this assignment you are asked to write a simple driver program an.pdf
in this assignment you are asked to write a simple driver program an.pdf
michardsonkhaicarr37
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Sriram Raj
 
In java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdfIn java , I want you to implement a Data Structure known as a Doubly.pdf
In java , I want you to implement a Data Structure known as a Doubly.pdf
aromalcom
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
curwenmichaela
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
Data Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptxData Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptx
RashidFaridChishti
 
public class Point {   Insert your name here    private dou.pdf
public class Point {    Insert your name here    private dou.pdfpublic class Point {    Insert your name here    private dou.pdf
public class Point {   Insert your name here    private dou.pdf
anandshingavi23
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
dbrienmhompsonkath75
 
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdfLabprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf
freddysarabia1
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
archgeetsenterprises
 

More from siennatimbok52331 (20)

SKIPPED hich level of biological orga.pdf
SKIPPED hich level of biological orga.pdfSKIPPED hich level of biological orga.pdf
SKIPPED hich level of biological orga.pdf
siennatimbok52331
 
please explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdfplease explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdf
siennatimbok52331
 
Please I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdfPlease I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdf
siennatimbok52331
 
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdfPlease answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
siennatimbok52331
 
Consider the security of a computer belonging to a criminal organiza.pdf
Consider the security of a computer belonging to a criminal organiza.pdfConsider the security of a computer belonging to a criminal organiza.pdf
Consider the security of a computer belonging to a criminal organiza.pdf
siennatimbok52331
 
Match the bones in column A with the characteristics in column B. Pla.pdf
Match the bones in column A with the characteristics in column B. Pla.pdfMatch the bones in column A with the characteristics in column B. Pla.pdf
Match the bones in column A with the characteristics in column B. Pla.pdf
siennatimbok52331
 
Is the mean age at which American children learn to walk less than 15.pdf
Is the mean age at which American children learn to walk less than 15.pdfIs the mean age at which American children learn to walk less than 15.pdf
Is the mean age at which American children learn to walk less than 15.pdf
siennatimbok52331
 
Introduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdfIntroduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdf
siennatimbok52331
 
Is this a Cohort Study What would be an example of a Cohort study.pdf
Is this a Cohort Study What would be an example of a Cohort study.pdfIs this a Cohort Study What would be an example of a Cohort study.pdf
Is this a Cohort Study What would be an example of a Cohort study.pdf
siennatimbok52331
 
Function of medium veins Function of medium veinsSolution.pdf
Function of medium veins Function of medium veinsSolution.pdfFunction of medium veins Function of medium veinsSolution.pdf
Function of medium veins Function of medium veinsSolution.pdf
siennatimbok52331
 
Explain the four factors of production. In what way are they rela.pdf
Explain the four factors of production. In what way are they rela.pdfExplain the four factors of production. In what way are they rela.pdf
Explain the four factors of production. In what way are they rela.pdf
siennatimbok52331
 
Discrete Math problem37 students use a variety of forms of transp.pdf
Discrete Math problem37 students use a variety of forms of transp.pdfDiscrete Math problem37 students use a variety of forms of transp.pdf
Discrete Math problem37 students use a variety of forms of transp.pdf
siennatimbok52331
 
Discuss the involvement of interest groups in the political circumst.pdf
Discuss the involvement of interest groups in the political circumst.pdfDiscuss the involvement of interest groups in the political circumst.pdf
Discuss the involvement of interest groups in the political circumst.pdf
siennatimbok52331
 
Determine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdfDetermine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdf
siennatimbok52331
 
Describe the difference between the lytic cycle and lysogeny when bac.pdf
Describe the difference between the lytic cycle and lysogeny when bac.pdfDescribe the difference between the lytic cycle and lysogeny when bac.pdf
Describe the difference between the lytic cycle and lysogeny when bac.pdf
siennatimbok52331
 
Describe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdfDescribe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdf
siennatimbok52331
 
Company B Company C None of them satisfy the requirements. Question9 .pdf
Company B Company C None of them satisfy the requirements. Question9 .pdfCompany B Company C None of them satisfy the requirements. Question9 .pdf
Company B Company C None of them satisfy the requirements. Question9 .pdf
siennatimbok52331
 
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdfCase 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
siennatimbok52331
 
A Correlation of zero means that (what)SolutionA value of zer.pdf
A Correlation of zero means that (what)SolutionA value of zer.pdfA Correlation of zero means that (what)SolutionA value of zer.pdf
A Correlation of zero means that (what)SolutionA value of zer.pdf
siennatimbok52331
 
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdfA bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
siennatimbok52331
 
SKIPPED hich level of biological orga.pdf
SKIPPED hich level of biological orga.pdfSKIPPED hich level of biological orga.pdf
SKIPPED hich level of biological orga.pdf
siennatimbok52331
 
please explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdfplease explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdf
siennatimbok52331
 
Please I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdfPlease I want a detailed complete answers for each part.Then make.pdf
Please I want a detailed complete answers for each part.Then make.pdf
siennatimbok52331
 
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdfPlease answer all of #5 After the completion of S phase, F.2F functi.pdf
Please answer all of #5 After the completion of S phase, F.2F functi.pdf
siennatimbok52331
 
Consider the security of a computer belonging to a criminal organiza.pdf
Consider the security of a computer belonging to a criminal organiza.pdfConsider the security of a computer belonging to a criminal organiza.pdf
Consider the security of a computer belonging to a criminal organiza.pdf
siennatimbok52331
 
Match the bones in column A with the characteristics in column B. Pla.pdf
Match the bones in column A with the characteristics in column B. Pla.pdfMatch the bones in column A with the characteristics in column B. Pla.pdf
Match the bones in column A with the characteristics in column B. Pla.pdf
siennatimbok52331
 
Is the mean age at which American children learn to walk less than 15.pdf
Is the mean age at which American children learn to walk less than 15.pdfIs the mean age at which American children learn to walk less than 15.pdf
Is the mean age at which American children learn to walk less than 15.pdf
siennatimbok52331
 
Introduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdfIntroduction to material science What kind of analyses methods will .pdf
Introduction to material science What kind of analyses methods will .pdf
siennatimbok52331
 
Is this a Cohort Study What would be an example of a Cohort study.pdf
Is this a Cohort Study What would be an example of a Cohort study.pdfIs this a Cohort Study What would be an example of a Cohort study.pdf
Is this a Cohort Study What would be an example of a Cohort study.pdf
siennatimbok52331
 
Function of medium veins Function of medium veinsSolution.pdf
Function of medium veins Function of medium veinsSolution.pdfFunction of medium veins Function of medium veinsSolution.pdf
Function of medium veins Function of medium veinsSolution.pdf
siennatimbok52331
 
Explain the four factors of production. In what way are they rela.pdf
Explain the four factors of production. In what way are they rela.pdfExplain the four factors of production. In what way are they rela.pdf
Explain the four factors of production. In what way are they rela.pdf
siennatimbok52331
 
Discrete Math problem37 students use a variety of forms of transp.pdf
Discrete Math problem37 students use a variety of forms of transp.pdfDiscrete Math problem37 students use a variety of forms of transp.pdf
Discrete Math problem37 students use a variety of forms of transp.pdf
siennatimbok52331
 
Discuss the involvement of interest groups in the political circumst.pdf
Discuss the involvement of interest groups in the political circumst.pdfDiscuss the involvement of interest groups in the political circumst.pdf
Discuss the involvement of interest groups in the political circumst.pdf
siennatimbok52331
 
Determine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdfDetermine which of these statements describing the cytochrome P450 f.pdf
Determine which of these statements describing the cytochrome P450 f.pdf
siennatimbok52331
 
Describe the difference between the lytic cycle and lysogeny when bac.pdf
Describe the difference between the lytic cycle and lysogeny when bac.pdfDescribe the difference between the lytic cycle and lysogeny when bac.pdf
Describe the difference between the lytic cycle and lysogeny when bac.pdf
siennatimbok52331
 
Describe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdfDescribe some of the different ways members of Congress can represen.pdf
Describe some of the different ways members of Congress can represen.pdf
siennatimbok52331
 
Company B Company C None of them satisfy the requirements. Question9 .pdf
Company B Company C None of them satisfy the requirements. Question9 .pdfCompany B Company C None of them satisfy the requirements. Question9 .pdf
Company B Company C None of them satisfy the requirements. Question9 .pdf
siennatimbok52331
 
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdfCase 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
Case 2S [symptoms] 10 month male presents to pediatrician’s offic.pdf
siennatimbok52331
 
A Correlation of zero means that (what)SolutionA value of zer.pdf
A Correlation of zero means that (what)SolutionA value of zer.pdfA Correlation of zero means that (what)SolutionA value of zer.pdf
A Correlation of zero means that (what)SolutionA value of zer.pdf
siennatimbok52331
 
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdfA bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
A bank had 5024 depositers, with an avevrage account of $512. Assume.pdf
siennatimbok52331
 
Ad

Recently uploaded (20)

apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
Kasdorf "Accessibility Essentials: A 2025 NISO Training Series, Session 5, Ac...
National Information Standards Organization (NISO)
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar RabbiPresentation on Tourism Product Development By Md Shaifullar Rabbi
Presentation on Tourism Product Development By Md Shaifullar Rabbi
Md Shaifullar Rabbi
 
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - WorksheetCBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
CBSE - Grade 8 - Science - Chemistry - Metals and Non Metals - Worksheet
Sritoma Majumder
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
Ad

Using NetBeansImplement a queue named QueueLL using a Linked List .pdf

  • 1. Using NetBeans Implement a queue named QueueLL using a Linked List (same as we did for the stack). This implementation must be used in all the following problems. Implement a queue QueueST using a stack (use StackLL). Test your implementations in the main with examples. Solution Answer:- import java.util.*; /* Class Node */ class Node { protected int data; protected Node link; /* Constructor */ public Node() { link = null; data = 0; } /* Constructor */ public Node(int d,Node n) { data = d; link = n; } /* Function to set link to next Node */ public void setLink(Node n) { link = n; } /* Function to set data to current Node */
  • 2. public void setData(int d) { data = d; } /* Function to get link to next node */ public Node getLink() { return link; } /* Function to get data from current Node */ public int getData() { return data; } } /* Class linkedQueue */ class linkedQueue { protected Node front, rear; public int size; /* Constructor */ public linkedQueue() { front = null; rear = null; size = 0; } /* Function to check if queue is empty */ public boolean isEmpty() { return front == null; } /* Function to get the size of the queue */ public int getSize()
  • 3. { return size; } /* Function to insert an element to the queue */ public void insert(int data) { Node nptr = new Node(data, null); if (rear == null) { front = nptr; rear = nptr; } else { rear.setLink(nptr); rear = rear.getLink(); } size++ ; } /* Function to remove front element from the queue */ public int remove() { if (isEmpty() ) throw new NoSuchElementException("Underflow Exception"); Node ptr = front; front = ptr.getLink(); if (front == null) rear = null; size-- ; return ptr.getData(); } /* Function to check the front element of the queue */ public int peek() { if (isEmpty() ) throw new NoSuchElementException("Underflow Exception");
  • 4. return front.getData(); } /* Function to display the status of the queue */ public void display() { System.out.print(" Queue = "); if (size == 0) { System.out.print("Empty "); return ; } Node ptr = front; while (ptr != rear.getLink() ) { System.out.print(ptr.getData()+" "); ptr = ptr.getLink(); } System.out.println(); } } /* Class LinkedQueueImplement */ public class LinkedQueueImplement { public static void main(String[] args) { Scanner scan = new Scanner(System.in); /* Creating object of class linkedQueue */ linkedQueue lq = new linkedQueue(); /* Perform Queue Operations */ System.out.println("Linked Queue Test "); char ch; do { System.out.println(" Queue Operations"); System.out.println("1. insert");
  • 5. System.out.println("2. remove"); System.out.println("3. peek"); System.out.println("4. check empty"); System.out.println("5. size"); int choice = scan.nextInt(); switch (choice) { case 1 : System.out.println("Enter integer element to insert"); lq.insert( scan.nextInt() ); break; case 2 : try { System.out.println("Removed Element = "+ lq.remove()); } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } break; case 3 : try { System.out.println("Peek Element = "+ lq.peek()); } catch (Exception e) { System.out.println("Error : " + e.getMessage()); } break; case 4 : System.out.println("Empty status = "+ lq.isEmpty()); break; case 5 :
  • 6. System.out.println("Size = "+ lq.getSize()); break; default : System.out.println("Wrong Entry "); break; } /* display queue */ lq.display(); System.out.println(" Do you want to continue (Type y or n) "); ch = scan.next().charAt(0); } while (ch == 'Y'|| ch == 'y'); } }