SlideShare a Scribd company logo
JAVA
need help with public Iterator iterator()
import java.util.Iterator;
/*
* GroupsQueue class supporting addition and removal of items
* with respect to a given number of priorities and with
* respect to the FIFO (first-in first-out) order for items
* with the same priority.
*
* An example, where GroupsQueue would be useful is the airline
* boarding process: every passenger gets assigned a priority,
* usually a number, e.g., group 1, group 2, group 3, etc. and
* the passengers line up at the end of the queue of their groups
* in a FIFO fashion; and, when removing from the GroupsQueue,
* i.e., when the passengers are boarding the plane, they get
* removed first by their group priorities and then by their FIFO
* ordering within that particular priority group.
*
* Your homework is to implement the below GroupsQueue data
* structure, so that it functions in the way described above.
*
* You may use the provided Queue class for implementing the
* GroupsQueue class.
*/
public class GroupsQueue implements Iterable {
private Node first;
private Node last;
private int n;
private static class Node {
private Item item;
private Node next;
}
public void Queue() {
first = null;
last = null;
n = 0;
}
// TODO : implement the data structure (20 points)
/**
* Initializes an empty GroupsQueue with g groups
* @return
*/
public GroupsQueue(int g) {
first = new Node<>();
last = first;
for(int i=1; i<=19; i++){
last.next = new Node<>();
last = last.next;
}
}
// TODO : implement the constructor (20 points)
/**
* Is this GroupsQueue empty?
*/
public boolean isEmpty() {
return size() == 0;
}
/**
* Returns the number of items in the GroupsQueue.
*/
public int size() {
return n; // TODO (20 points)
}
/**
* Adds the item to this GroupsQueue with group id = gId.
*/
public void add(Item item, int gId) {
Node oldlast = last;
last = new Node();
last.item = item;
last.next = null;
if (isEmpty()) first = last;
else{
oldlast.next = last;
}
n++;
}
// TODO (20 points)
/**
* Removes and returns the item with the lowest group id
*/
public Item remove() {
Node temp = first;
Node prev = first;
Item minGid;
if (! isEmpty())
{
minGid = first.item;
}
else
{
return null;
}
while(temp!= null)
{
prev = temp;
temp = temp.next;
if (temp.item == minGid)
{
minGid = (Item) temp.item;
}
}
if (minGid == first.item)
{
first = first.next;
}
else
{
prev.next = prev.next.next;
}
n--;
return minGid;
}// TODO (20 points)
/**
* Returns an iterator that iterates over the items in this GroupsQueue
* in group id order (lowest id first) and in FIFO order in each group.
*/
public Iterator iterator() {
// TODO
// BONUS (20 points)
return null;
}
}
Solution
Implementation given here seems to have many logical errors.
Here is the code given for GroupQueue:
package groupqueue;
public class GroupQueue{
/**
* n is number of queues maintained. and queues is array of all queues maintained by
GroupQueue.
* here there are n groups . so maintain n queues and each queue represent one group.
*/
public int n;
public Queue[] queues;
public GroupQueue(int n){
this.n =n;
this.queues = new Queue[n]; //initialize array of queues with n number of groups
}
//is this GroupQueue empty ?
public boolean isEmpty() {
for(int i=0; i tempNode ;
for(int i=0; i newNode= new Node(item);
if(queues[gId].first== null){ //when queue is empty first and last point to same new node.
queues[gId].first= newNode;
queues[gId].last= newNode;
}
else{
queues[gId].last.next= newNode;
queues[gId].last= newNode;
}
}
public Item remove(){
if(isEmpty()) return null;
int i=0;
// find for a queue which has at leats one element.
while(queues[i].first== null){
i++;
}
// now ith queue will have at least one element
Node temp =queues[i].first; // return the first element from ith queue
queues[i].first= queues[i].first.next; //First variable will point to second element of queue now.
return temp.item;
}
// method to iterate through all elements of GroupQueue and prints them in ascending order of
group id.
// here for a one group , elements will be printed in FIFO manner of queue of that group .
// here no need to retun anything , as we are printing all elements in function itself.
public void iterator() {
Node temp;
for(int i=0 ; i{
public Item item;
public Node next;
public Node(Item item){
this.item= item ;
this.next= null;
}
}
public static class Item{
public int Itemdata;
public Item(int d){
this.Itemdata=d;
}
}
public static class Queue{
public Node first;
public Node last;
public Queue(){
first = last= null; //initially first and last pointer are null for each queue.
}
}
}

More Related Content

Similar to JAVAneed help with public IteratorItem iterator()import java.u.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
mail931892
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
rajat630669
 
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
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
BlakeSGMHemmingss
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
siennatimbok52331
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdf
gudduraza28
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
fcaindore
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
asarudheen07
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
arihantpatna
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
aioils
 
I have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdfI have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdf
JUSTSTYLISH3B2MOHALI
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
brijmote
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
aggarwalopticalsco
 
Java Generics
Java GenericsJava Generics
Java Generics
jeslie
 
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
 
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
 
package algs13;import stdlib.;import java.util.Iterator;im.docx
package algs13;import  stdlib.;import java.util.Iterator;im.docxpackage algs13;import  stdlib.;import java.util.Iterator;im.docx
package algs13;import stdlib.;import java.util.Iterator;im.docx
gerardkortney
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
angelsfashion1
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
fathimafancyjeweller
 

Similar to JAVAneed help with public IteratorItem iterator()import java.u.pdf (20)

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
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.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
 
EmptyCollectionException-java -- - Represents the situation in which.docx
EmptyCollectionException-java --  - Represents the situation in which.docxEmptyCollectionException-java --  - Represents the situation in which.docx
EmptyCollectionException-java -- - Represents the situation in which.docx
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdf
 
This is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdfThis is problem is same problem which i submitted on 22017, I just.pdf
This is problem is same problem which i submitted on 22017, I just.pdf
 
import java-util--- public class MyLinkedList{ public static void.pdf
import java-util---  public class MyLinkedList{    public static void.pdfimport java-util---  public class MyLinkedList{    public static void.pdf
import java-util--- public class MyLinkedList{ public static void.pdf
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
Here is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdfHere is what I got so far, I dont know how to write union, interse.pdf
Here is what I got so far, I dont know how to write union, interse.pdf
 
Please do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdfPlease do parts labeled TODO LinkedList.java Replace.pdf
Please do parts labeled TODO LinkedList.java Replace.pdf
 
I have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdfI have a stack in Java populated with integers. Im trying to compa.pdf
I have a stack in Java populated with integers. Im trying to compa.pdf
 
solution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdfsolution in c++program Program to implement a queue using two .pdf
solution in c++program Program to implement a queue using two .pdf
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
 
Java Generics
Java GenericsJava Generics
Java Generics
 
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
 
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
 
package algs13;import stdlib.;import java.util.Iterator;im.docx
package algs13;import  stdlib.;import java.util.Iterator;im.docxpackage algs13;import  stdlib.;import java.util.Iterator;im.docx
package algs13;import stdlib.;import java.util.Iterator;im.docx
 
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf #ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
#ifndef LINKED_LIST_ #define LINKED_LIST_ templateclass It.pdf
 
Please review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdfPlease review my code (java)Someone helped me with it but i cannot.pdf
Please review my code (java)Someone helped me with it but i cannot.pdf
 

More from fcsondhiindia

LUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdf
LUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdfLUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdf
LUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdf
fcsondhiindia
 
Let A be an n n matrix. Which of the following are TRUE I. If A i.pdf
Let A be an n n matrix. Which of the following are TRUE I. If A i.pdfLet A be an n n matrix. Which of the following are TRUE I. If A i.pdf
Let A be an n n matrix. Which of the following are TRUE I. If A i.pdf
fcsondhiindia
 
How does PERT technique compare with estimating or forecasting techn.pdf
How does PERT technique compare with estimating or forecasting techn.pdfHow does PERT technique compare with estimating or forecasting techn.pdf
How does PERT technique compare with estimating or forecasting techn.pdf
fcsondhiindia
 
in 4 paragraphs explain Profit Sharing in the US between Management .pdf
in 4 paragraphs explain Profit Sharing in the US between Management .pdfin 4 paragraphs explain Profit Sharing in the US between Management .pdf
in 4 paragraphs explain Profit Sharing in the US between Management .pdf
fcsondhiindia
 
I have the source code for three separate java programs (TestVending.pdf
I have the source code for three separate java programs (TestVending.pdfI have the source code for three separate java programs (TestVending.pdf
I have the source code for three separate java programs (TestVending.pdf
fcsondhiindia
 
How is the urinary system is involved in regulating the pH in bodily.pdf
How is the urinary system is involved in regulating the pH in bodily.pdfHow is the urinary system is involved in regulating the pH in bodily.pdf
How is the urinary system is involved in regulating the pH in bodily.pdf
fcsondhiindia
 
Find a polynomial that describes the shaded area. SolutionArea.pdf
Find a polynomial that describes the shaded area.  SolutionArea.pdfFind a polynomial that describes the shaded area.  SolutionArea.pdf
Find a polynomial that describes the shaded area. SolutionArea.pdf
fcsondhiindia
 
Explain the common interest logic and the economic logic of .pdf
Explain the common interest logic and the economic logic of .pdfExplain the common interest logic and the economic logic of .pdf
Explain the common interest logic and the economic logic of .pdf
fcsondhiindia
 
Does privacy always guarantee integrity. Justify your answerSolu.pdf
Does privacy always guarantee integrity. Justify your answerSolu.pdfDoes privacy always guarantee integrity. Justify your answerSolu.pdf
Does privacy always guarantee integrity. Justify your answerSolu.pdf
fcsondhiindia
 
Distinguish between the GAAP and IFRS standards for internal .pdf
Distinguish between the GAAP and IFRS standards for internal .pdfDistinguish between the GAAP and IFRS standards for internal .pdf
Distinguish between the GAAP and IFRS standards for internal .pdf
fcsondhiindia
 
Describe how pH inhibit microbe growth.SolutionMost of the pat.pdf
Describe how pH inhibit microbe growth.SolutionMost of the pat.pdfDescribe how pH inhibit microbe growth.SolutionMost of the pat.pdf
Describe how pH inhibit microbe growth.SolutionMost of the pat.pdf
fcsondhiindia
 
Write the C code to create a data structure named window that con.pdf
Write the C code to create a data structure named window that con.pdfWrite the C code to create a data structure named window that con.pdf
Write the C code to create a data structure named window that con.pdf
fcsondhiindia
 
Write 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdf
Write 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdfWrite 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdf
Write 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdf
fcsondhiindia
 
Who are the people directly involved in the collective bargaining pr.pdf
Who are the people directly involved in the collective bargaining pr.pdfWho are the people directly involved in the collective bargaining pr.pdf
Who are the people directly involved in the collective bargaining pr.pdf
fcsondhiindia
 
Contracts or agreements can sometimes create financial contingencies.pdf
Contracts or agreements can sometimes create financial contingencies.pdfContracts or agreements can sometimes create financial contingencies.pdf
Contracts or agreements can sometimes create financial contingencies.pdf
fcsondhiindia
 
Which of the following is an equation of the line that passes through.pdf
Which of the following is an equation of the line that passes through.pdfWhich of the following is an equation of the line that passes through.pdf
Which of the following is an equation of the line that passes through.pdf
fcsondhiindia
 
When more than one structural arrangement of elements is possible fo.pdf
When more than one structural arrangement of elements is possible fo.pdfWhen more than one structural arrangement of elements is possible fo.pdf
When more than one structural arrangement of elements is possible fo.pdf
fcsondhiindia
 
Click to add title 2. Explain the concept of African Diaspora and dis.pdf
Click to add title 2. Explain the concept of African Diaspora and dis.pdfClick to add title 2. Explain the concept of African Diaspora and dis.pdf
Click to add title 2. Explain the concept of African Diaspora and dis.pdf
fcsondhiindia
 
Based on the following data, what is the quick ratio, rounded to one.pdf
Based on the following data, what is the quick ratio, rounded to one.pdfBased on the following data, what is the quick ratio, rounded to one.pdf
Based on the following data, what is the quick ratio, rounded to one.pdf
fcsondhiindia
 
ATP production during glycolysis;requires an enzymeoccurs in the.pdf
ATP production during glycolysis;requires an enzymeoccurs in the.pdfATP production during glycolysis;requires an enzymeoccurs in the.pdf
ATP production during glycolysis;requires an enzymeoccurs in the.pdf
fcsondhiindia
 

More from fcsondhiindia (20)

LUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdf
LUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdfLUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdf
LUS (a) Prepare the jounal entry to recerd the proceeds of the note. .pdf
 
Let A be an n n matrix. Which of the following are TRUE I. If A i.pdf
Let A be an n n matrix. Which of the following are TRUE I. If A i.pdfLet A be an n n matrix. Which of the following are TRUE I. If A i.pdf
Let A be an n n matrix. Which of the following are TRUE I. If A i.pdf
 
How does PERT technique compare with estimating or forecasting techn.pdf
How does PERT technique compare with estimating or forecasting techn.pdfHow does PERT technique compare with estimating or forecasting techn.pdf
How does PERT technique compare with estimating or forecasting techn.pdf
 
in 4 paragraphs explain Profit Sharing in the US between Management .pdf
in 4 paragraphs explain Profit Sharing in the US between Management .pdfin 4 paragraphs explain Profit Sharing in the US between Management .pdf
in 4 paragraphs explain Profit Sharing in the US between Management .pdf
 
I have the source code for three separate java programs (TestVending.pdf
I have the source code for three separate java programs (TestVending.pdfI have the source code for three separate java programs (TestVending.pdf
I have the source code for three separate java programs (TestVending.pdf
 
How is the urinary system is involved in regulating the pH in bodily.pdf
How is the urinary system is involved in regulating the pH in bodily.pdfHow is the urinary system is involved in regulating the pH in bodily.pdf
How is the urinary system is involved in regulating the pH in bodily.pdf
 
Find a polynomial that describes the shaded area. SolutionArea.pdf
Find a polynomial that describes the shaded area.  SolutionArea.pdfFind a polynomial that describes the shaded area.  SolutionArea.pdf
Find a polynomial that describes the shaded area. SolutionArea.pdf
 
Explain the common interest logic and the economic logic of .pdf
Explain the common interest logic and the economic logic of .pdfExplain the common interest logic and the economic logic of .pdf
Explain the common interest logic and the economic logic of .pdf
 
Does privacy always guarantee integrity. Justify your answerSolu.pdf
Does privacy always guarantee integrity. Justify your answerSolu.pdfDoes privacy always guarantee integrity. Justify your answerSolu.pdf
Does privacy always guarantee integrity. Justify your answerSolu.pdf
 
Distinguish between the GAAP and IFRS standards for internal .pdf
Distinguish between the GAAP and IFRS standards for internal .pdfDistinguish between the GAAP and IFRS standards for internal .pdf
Distinguish between the GAAP and IFRS standards for internal .pdf
 
Describe how pH inhibit microbe growth.SolutionMost of the pat.pdf
Describe how pH inhibit microbe growth.SolutionMost of the pat.pdfDescribe how pH inhibit microbe growth.SolutionMost of the pat.pdf
Describe how pH inhibit microbe growth.SolutionMost of the pat.pdf
 
Write the C code to create a data structure named window that con.pdf
Write the C code to create a data structure named window that con.pdfWrite the C code to create a data structure named window that con.pdf
Write the C code to create a data structure named window that con.pdf
 
Write 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdf
Write 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdfWrite 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdf
Write 4 to 5 paragraphs aboutthe Dyn cyber attack that occurred in.pdf
 
Who are the people directly involved in the collective bargaining pr.pdf
Who are the people directly involved in the collective bargaining pr.pdfWho are the people directly involved in the collective bargaining pr.pdf
Who are the people directly involved in the collective bargaining pr.pdf
 
Contracts or agreements can sometimes create financial contingencies.pdf
Contracts or agreements can sometimes create financial contingencies.pdfContracts or agreements can sometimes create financial contingencies.pdf
Contracts or agreements can sometimes create financial contingencies.pdf
 
Which of the following is an equation of the line that passes through.pdf
Which of the following is an equation of the line that passes through.pdfWhich of the following is an equation of the line that passes through.pdf
Which of the following is an equation of the line that passes through.pdf
 
When more than one structural arrangement of elements is possible fo.pdf
When more than one structural arrangement of elements is possible fo.pdfWhen more than one structural arrangement of elements is possible fo.pdf
When more than one structural arrangement of elements is possible fo.pdf
 
Click to add title 2. Explain the concept of African Diaspora and dis.pdf
Click to add title 2. Explain the concept of African Diaspora and dis.pdfClick to add title 2. Explain the concept of African Diaspora and dis.pdf
Click to add title 2. Explain the concept of African Diaspora and dis.pdf
 
Based on the following data, what is the quick ratio, rounded to one.pdf
Based on the following data, what is the quick ratio, rounded to one.pdfBased on the following data, what is the quick ratio, rounded to one.pdf
Based on the following data, what is the quick ratio, rounded to one.pdf
 
ATP production during glycolysis;requires an enzymeoccurs in the.pdf
ATP production during glycolysis;requires an enzymeoccurs in the.pdfATP production during glycolysis;requires an enzymeoccurs in the.pdf
ATP production during glycolysis;requires an enzymeoccurs in the.pdf
 

Recently uploaded

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 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
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
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
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
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
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
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
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
"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
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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
 
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
 
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
 

Recently uploaded (20)

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 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
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
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
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
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
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
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
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
"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...
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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 Á...
 
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
 

JAVAneed help with public IteratorItem iterator()import java.u.pdf

  • 1. JAVA need help with public Iterator iterator() import java.util.Iterator; /* * GroupsQueue class supporting addition and removal of items * with respect to a given number of priorities and with * respect to the FIFO (first-in first-out) order for items * with the same priority. * * An example, where GroupsQueue would be useful is the airline * boarding process: every passenger gets assigned a priority, * usually a number, e.g., group 1, group 2, group 3, etc. and * the passengers line up at the end of the queue of their groups * in a FIFO fashion; and, when removing from the GroupsQueue, * i.e., when the passengers are boarding the plane, they get * removed first by their group priorities and then by their FIFO * ordering within that particular priority group. * * Your homework is to implement the below GroupsQueue data * structure, so that it functions in the way described above. * * You may use the provided Queue class for implementing the * GroupsQueue class. */ public class GroupsQueue implements Iterable { private Node first; private Node last; private int n; private static class Node { private Item item; private Node next; } public void Queue() {
  • 2. first = null; last = null; n = 0; } // TODO : implement the data structure (20 points) /** * Initializes an empty GroupsQueue with g groups * @return */ public GroupsQueue(int g) { first = new Node<>(); last = first; for(int i=1; i<=19; i++){ last.next = new Node<>(); last = last.next; } } // TODO : implement the constructor (20 points) /** * Is this GroupsQueue empty? */ public boolean isEmpty() { return size() == 0; } /** * Returns the number of items in the GroupsQueue. */ public int size() { return n; // TODO (20 points) } /** * Adds the item to this GroupsQueue with group id = gId. */
  • 3. public void add(Item item, int gId) { Node oldlast = last; last = new Node(); last.item = item; last.next = null; if (isEmpty()) first = last; else{ oldlast.next = last; } n++; } // TODO (20 points) /** * Removes and returns the item with the lowest group id */ public Item remove() { Node temp = first; Node prev = first; Item minGid; if (! isEmpty()) { minGid = first.item; } else { return null; } while(temp!= null) { prev = temp; temp = temp.next; if (temp.item == minGid) {
  • 4. minGid = (Item) temp.item; } } if (minGid == first.item) { first = first.next; } else { prev.next = prev.next.next; } n--; return minGid; }// TODO (20 points) /** * Returns an iterator that iterates over the items in this GroupsQueue * in group id order (lowest id first) and in FIFO order in each group. */ public Iterator iterator() { // TODO // BONUS (20 points) return null; } } Solution Implementation given here seems to have many logical errors. Here is the code given for GroupQueue: package groupqueue; public class GroupQueue{ /** * n is number of queues maintained. and queues is array of all queues maintained by
  • 5. GroupQueue. * here there are n groups . so maintain n queues and each queue represent one group. */ public int n; public Queue[] queues; public GroupQueue(int n){ this.n =n; this.queues = new Queue[n]; //initialize array of queues with n number of groups } //is this GroupQueue empty ? public boolean isEmpty() { for(int i=0; i tempNode ; for(int i=0; i newNode= new Node(item); if(queues[gId].first== null){ //when queue is empty first and last point to same new node. queues[gId].first= newNode; queues[gId].last= newNode; } else{ queues[gId].last.next= newNode; queues[gId].last= newNode; } } public Item remove(){ if(isEmpty()) return null; int i=0; // find for a queue which has at leats one element. while(queues[i].first== null){ i++; }
  • 6. // now ith queue will have at least one element Node temp =queues[i].first; // return the first element from ith queue queues[i].first= queues[i].first.next; //First variable will point to second element of queue now. return temp.item; } // method to iterate through all elements of GroupQueue and prints them in ascending order of group id. // here for a one group , elements will be printed in FIFO manner of queue of that group . // here no need to retun anything , as we are printing all elements in function itself. public void iterator() { Node temp; for(int i=0 ; i{ public Item item; public Node next; public Node(Item item){ this.item= item ; this.next= null; } } public static class Item{ public int Itemdata; public Item(int d){ this.Itemdata=d; } } public static class Queue{ public Node first; public Node last; public Queue(){
  • 7. first = last= null; //initially first and last pointer are null for each queue. } } }