Computers and Technology
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]

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 16:30, jonnys412
Margins can be modified in the page layout tab or by using
Answers: 2
image
Computers and Technology, 22.06.2019 11:30, genyjoannerubiera
What does a cascading style sheet resolve a conflict over rules for an element? a. the rule affecting the most content wins b. the rule affecting the most content loses c. the rule with the most specific selector loses d. the rule with the most specific selector wins
Answers: 2
image
Computers and Technology, 22.06.2019 15:30, micahpauleen748
In a compound condition, both conditions on either side of the logical operator and must be true for the overall condition to be true. a: true b: false
Answers: 1
image
Computers and Technology, 22.06.2019 16:30, mesposito
Technician a says that a dry sump system uses no oil storage sump under the engine. technician b says that a wet sump system uses no oil storage sump under the engine. who is correct?
Answers: 3
Do you know the correct answer?
11. Write a method that accepts a Queue of String as its parameter, this method separates the even l...

Questions in other subjects:

Konu
Geography, 21.05.2020 06:58