Write the function evens which takes in a queue by reference and changes it to only contain the even elements. That is, if the q
ueue initially contains 3, 6, 1, 7, 8 then after calling odds, the queue will contain 6, 8. Note that the order of the elements in the queue remains the same. For full credit, no additional data structures (queues, stacks, vectors, etc.) should be used. Assume all libraries needed for your implementation have already been included.
The following code is written in Java it goes through the queue that was passed as an argument, loops through it and removes all the odd numbers, leaving only the even numbers in the queue. It does not add any more data structures and finally returns the modified queue when its done.
public static Queue<Integer> evens(Queue<Integer> queue) {
A function does not require the number of times that the <em>code script needs to be executed
</em>
When we go for large programming, ie. while creating projects, we can invoke function from one file to another based on the access <em>specifier mentioned for the function.
</em>
There is a stack call created in the memory whenever a <em>function is called.
</em>
<em>LOOP
:</em>
Whereas the number of times that the loop has to be <em>executed must be defined
</em>
A loop cannot be called, it can be used only the code block in <em>which it is present.
</em>
There is not overhead of creating a stack since it is not invoked and there is no <em>transfer of control from one module to another
</em>