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');
}
}

More Related Content

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

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
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docx
shericehewat
 
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
Sriram Raj
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Zidny Nafan
 
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
 

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
 
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
 
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
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
Given the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docxGiven the following ADT definition of a stack to use stack .docx
Given the following ADT definition of a stack to use stack .docx
 
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
 
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
 
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
 
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
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
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
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
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
 
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
 
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
 
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
 
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
 
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
 

More from 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
 

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
 
please explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdfplease explain transcription and translationSolutionAnsTran.pdf
please explain transcription and translationSolutionAnsTran.pdf
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 
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
 

Recently uploaded

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 

Recently uploaded (20)

"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 

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'); } }