Q1: Write a non-recursive algorithm to compute the size of a stack. Make sure the stack does not lose its elements. Q2:
Posted: Thu Jun 02, 2022 7:43 am
Q1: Write a non-recursive algorithm to compute the size of a stack. Make sure the stack does not lose its elements. Q2: Write a recursive algorithm to compute the size of a stack. Make sure the stack does not lose its elements. Q3: Write a recursive method that calculates the sum of odd elements of a LinkedList. Q4: Write an algorithm to move a stack into a queue and return the queue to the caller. Q5: Using the specification of the Stack ADT, write a method to output the contents of a stack in reverse order. For example, if the stack contents are 1 2 3 4 with 4 at the top, the output should be 1 2 3 and 4. (You may use another stack to store temporary data) Q6: Using the specification of the Stack ADT, write a method to count the number of elements in a stack. The stack should be unchanged after the operation. (You may use another stack to store temporary data) Q7: Using the specification of the Stack ADT, write a method to delete every occurrence of an element from the stack leaving the order of other elements unchanged. (You may use another stack to store temporary data) Q8: Using the specification of the Stack ADT, write a method to return every third element from the stack. For example, if the contents of the stack are 1 2 3 4 5 6 7 8 9 then following should be outputted: 7,4 and 1. (You may use another stack to store temporary data)