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 18:30
The "instance" relationship shows that something is an object of a
Answers: 1
question
Computers and Technology, 24.06.2019 01:30
Hazel has just finished adding pictures to her holiday newsletter. she decides to crop an image. what is cropping an image?
Answers: 1
question
Computers and Technology, 24.06.2019 15:00
Universal windows platform is designed for which windows 10 version?
Answers: 1
question
Computers and Technology, 24.06.2019 18:30
Dereck works for long hours on his computer.  he frequently experiences physical strain by the end of the day because he does not follow an important rule of ergonomics with respect to the use of keyboards.  which of the following actions of dereck could lead to physical strain? a.  placing the keyboard exactly in front of him while typingb.  keeping hands and wrists straight while typingc.  using wrist pads throughout the dayd.  pounding at the keys on the keyboard while typinge.  resting his hands on the keyboard when he is not typing
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
History, 21.06.2019 21:00
Questions on the website: 13722360