First writing a pseudocode algorithm then translating it into a working Java pro
ID: 3720919 • Letter: F
Question
First writing a pseudocode algorithm then translating it into a working Java program. Add comments to explain what the parts are doing.
- What is meant by an array element?
- Present significant differences between Stack and Queue.
- What is infix notation and postfix notation? Show an example for both.
Write a program that uses a stack to reverse the contents of an array of integers. In the main part, ten numbers are prompted to be pushed onto the stack. There is a procedure which is called as 'reverse' in the program for popping the stack and displaying the values in the reverse of the order they were entered in. To develop the program, you can design an function called 'undo' for the user entering the list of numbers. This function could solve the problem when the user enters a wrong number and give another chance to go back and enter the number to replace the last one.
Trace the following pseudocode showing the contents of the stack after each invocation (step) by drawing a diagram of the state of the stack for each invocation.
Declare MyStack as Stack
MyStack.Push (“Google home”)?
MyStack.Push (“Football match”)?
MyStack.Pop
MyStack.Pop
MyStack.Push (“Google home”)?
MyStack.Push (“Basketball match”)
MyStack.Push (“Match results”)?
MyStack.Pop
MyStack.Pop
MyStack.Pop
Explanation / Answer
an array is basically a data structure which have collection of elements (an element can be a values or variables) having an index to find it . An array is stored so that the position of each element can be computed from its index tuple by a mathematical formula.
Differences Between Stack and Queue
Stack and Queue both are the non-primitive data structures. But the differences between these are - Stack uses LIFO (last in first out) method to access and add data elements while Queue uses FIFO (First in first out) method to access and add data elements.
Structural difference - In the Stack same end is used to insert and delete elements while in Queue one end is used for insertion, i.e., rear end and another end is used for deletion of elements, i.e., front end
Operations performed by Stack name as Push and Pop while in Queue it is Enqueue and dequeue.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.