Question

In: Computer Science

1. What is the ouput (what are in the Bag) when the 2 below lines are...

1. What is the ouput (what are in the Bag) when the 2 below lines are executed? Please show the steps. String[] items = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"}; testAdd(aBag, items);

2.

What is the output (what are in the Bag) when the 3 below lines are executed? Please show the steps.

String[] testString = { "X", "Y", "Z" };

aBag.removeAllOccurences(testString);

displayBag(aBag);

Solutions

Expert Solution

In this answer, I am assuming the bag is empty initially.

aBag = { }

(1)

String[] items = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"};

testAdd(aBag, items);

When the above two lines are executed, then all the strings in the items array will be added to the bag.

Output: aBag = {"Z", "Y", "Y", "X", "S", "C", "A", "E", "M"}

(2)

String[] testString = { "X", "Y", "Z" };

aBag.removeAllOccurences(testString);

displayBag(aBag);

When the above three lines are executed, then all the strings in the testString array will be removed from the bag.

If there are multiple occurrences of any string, all occurrences will be removed.

There is one occurrence of ''X", two occurrences of "Y", one occurrence of "Z" in abag, those strings will be removed from the bag, and the output bag contents will be:

Output: aBag = {"S", "C", "A", "E", "M"}

----------------------------------------

I hope this helps you,

Please rate this answer if it helped you,
Please comment on this answer, for any further discussion

Thanks for the opportunity


Related Solutions

1. When can an economy increase the production of one good without reducing the ouput of...
1. When can an economy increase the production of one good without reducing the ouput of another? 2. What is the difference between Productive Efficiency and Allocative Efficiency? Can you provide examples that can help illustrate the difference between the two?
answer only in 2 or 3 lines 1. When conducting needs analysis what aspects have to...
answer only in 2 or 3 lines 1. When conducting needs analysis what aspects have to be tackled? 2. List some considerations when designing the training program. 3. List the training and development methods available in the implementation phase. 4. List ways to evaluate the training. 5. What is orientation? Explain. 6. What are the benefits of orientation? 7. List the characteristics of successful orientation process. 8. What is career development? Explain. 9. What are some favorable conditions for career...
what is time management ? 2 lines please what happens when your are not practicing good...
what is time management ? 2 lines please what happens when your are not practicing good time management skills? 5 lines answer please. how effecttively can you used your 168 hrs per week ?? 5 lines answer pleaee
What is the ouput of the following code? void loop(int num) { for(int i = 1;...
What is the ouput of the following code? void loop(int num) { for(int i = 1; i < num; ++i) { for(int j = 0; j < 5; ++j) { cout << j; } } } int main() { loop(3); return 0; }
Applying a ice bag 1. What is ice used for in physical therapy? 2. What is...
Applying a ice bag 1. What is ice used for in physical therapy? 2. What is the easiest way to apply ice at home? 3. In addition to the ice bag what will also help reduce inflammation? 4. How long should you apply ice for, what can happen if applied longer?
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output...
Write Lexical Analyzer program in C language. Below is the sample input and ouput. /* output Enter the string: if(a<b){a=10;} Tokens are identifier :if punctuation mark : ( identifier :a operator:< identifier :b punctuation mark : ) punctuation mark : { identifier :a operator:= constant :10 punctuation mark : ; punctuation mark : } */
Explain in 2 to 3 lines. 1.When we open a position, the costs are different between...
Explain in 2 to 3 lines. 1.When we open a position, the costs are different between an options contract and a futures contract. Explain the difference between a premium and a margin account. Be sure to explain the various types of margins that are required and what costs each type of contract has. 2.Explain the idea of the "cost of carry" as it applies to futures contracts. Specifically, what factors can influence the difference between a spot and futures/forward price...
1. In engineering drawing what are hidden lines used for? 2. What is sectioning used for...
1. In engineering drawing what are hidden lines used for? 2. What is sectioning used for and how is it represented? 3. Why are three phase power systems represented using only single lines? 4. What is CAM, Briefly explain what it is? 5. In one sentence explain what Finite Element Analysis (FEA), name three advantages of using FEA.
What is the output of the StackQueueMystery algorithm (below) when we have enqueued 1, 2, 5,...
What is the output of the StackQueueMystery algorithm (below) when we have enqueued 1, 2, 5, 6, 3, 7, 4, 10, 8, 9 on q and pushed 8, 6, 9, 7, 10, 5, 4, 3, 2, 1 on stk (in that order) before calling this algorithm. Show your work. StackQueueMystery: Input: stk: stack with integers 1-n Input: q: queue with integers 1-n Input: n: size and range of stk and q Pseudocode: count = 0 while stk and q are...
1. What happens to the human being when his/her temperature drops below 36 and 2. What...
1. What happens to the human being when his/her temperature drops below 36 and 2. What happens to them when their temperature goes above 49. 3. What changes happen to the human body especially when the body temperature drops much lower than 34 and much higher than 42 degrees Celsius? (Remember here we are discussing the internal temperature of the human body and its effect on their being).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT