Question: Write a pseudocode algorithm that returns the average of the elements in a stack. Also, give the Big O of your algorithm. Your algorithm must

Write a pseudocode algorithm that returns the average of the elements in a stack. Also, give the Big O of your algorithm. Your algorithm must not change the final state of the stack (i.e. the stack should be the same at the end of your function).
For example, given the Stack with contents top ->[2,4,5,1,3] would return 3. The method signature should be calculate_average(Stack list)=> float.
Recall that the available methods for a stack are:
push
pop
peek
isEmpty
size
clear

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!