subject
Computers and Technology, 15.12.2020 03:00 nooope

11. Write a method that accepts a Queue of String as its parameter, this method separates the even length string from the odd length string (even length Strings on the left side and odd length String on the right side. You can use java’s Queue class. Remember that you can only take elements from the beginning of Queue and you can add element to the end of the Queue. You can only use one extra Stack storage. Solutions using more that one stack will get zero points. Remember that Queue is an interface in java meaning that you can declare a Queue but you need to instantiate as a LinkList. (refer to the provided lectures) Here is the output: Queue my = new LinkedList ();
my. add("hello");
my. add("Doctor");
my. add("for");
my. add("after");
my. add("");
my. add("");
my. add("never");
my. add("fully");
System. out. println(my);
seperate(my);
System. out. println(my);
public static void seperate(Queue names)
{
Stack even = new Stack();
int index = 0;
while(index < names. size())
{
String s = names. remove();//removes the elemnt at the begining of the list
//names. remove(0);
if(s. length() % 2 == 0)
even. push(s);
else
names. add(s);
index++;
}
while(!even. isEmpty())
{
names. add((String)even. pop());
}

}
}

Content of the Queue before the method call:
[hello, Doctor, for, after, , , never, fully]
Content of the Queue after the method call
[never, fully, hello, for, after, , , Doctor]

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 21:00
The average cost of one year at a private college in 2012-2013 is $43,289. the average grant aid received by a student at a private college in 2012-2013 is $15,680.   what is the average student contribution for one year at a private college in 2012-2013?
Answers: 3
question
Computers and Technology, 22.06.2019 23:30
Select all that apply. which of the following are proofreading options included in microsoft word? spell check find replace grammar check formatting check
Answers: 1
question
Computers and Technology, 24.06.2019 01:00
What shows the web address of the page that is currently displayed in the workspace? status window toolbar location bar internet box
Answers: 1
question
Computers and Technology, 24.06.2019 08:00
Can someone work out the answer as it comes up in one of my computer science exams and i don't understand the cryptovariables
Answers: 1
You know the right answer?
11. Write a method that accepts a Queue of String as its parameter, this method separates the even l...
Questions
question
Mathematics, 28.05.2021 03:30
question
Mathematics, 28.05.2021 03:30
Questions on the website: 13722367