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 22:30
Alex’s family members live in different parts of the world. they would like to discuss the wedding plans of one of their distant relatives. however, alex wants all the family members to talk to each other simultaneously so that they can make decisions quickly. which mode of internet communication should they use? a. blog b. email c. wiki d. message board e. instant messaging
Answers: 2
question
Computers and Technology, 23.06.2019 00:30
Knowing that the central portion of link bd has a uniform cross sectional area of 800 mm2 , determine the magnitude of the load p for which the normal stress in link bd is 50 mpa. (hint: link bd is a two-force member.) ans: p = 62.7 kn
Answers: 2
question
Computers and Technology, 23.06.2019 03:00
Jason, samantha, ravi, sheila, and ankit are preparing for an upcoming marathon. each day of the week, they run a certain number of miles and write them into a notebook. at the end of the week, they would like to know the number of miles run each day, the total miles for the week, and average miles run each day. write a program to them analyze their data. your program must contain parallel arrays: an array to store the names of the runners and a two-dimensional array of five rows and seven columns to store the number of miles run by each runner each day. furthermore, your program must contain at least the following functions: a function to read and store the runners’ names and the numbers of miles run each day; a function to find the total miles run by each runner and the average number of miles run each day; and a function to output the results. (you may assume that the input data is stored in a file and each line of data is in the following form: runnername milesday1 milesday2 milesday3 milesday4 milesday5 milesday6 milesday7.)
Answers: 3
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