CSE 2221 Final Exam | 80 Questions with 100% Correct Answers | Verified | Latest Update 2024
Why is the container class called Stack? - ✔✔It follows the same sort of organization and manipulation type that a stack in the program execution would perform LIFO (last-in-first-out)
LIFO - ✔✔last in first out
How is a Stack different than the queue? - ✔✔it is like a "dual" A queue is first in first out, while stack is last in first out
What are the three methods of StackKernel? - ✔✔ push pop length
What are the three methods of the Stack Interface? - ✔✔ top replaceTop flip
What mathematical model is Stack modeled by? - ✔✔Modeled by mathematical string of T
How many constructors for Stack? - ✔✔only 1, which is empty, creates an empty stack
What does the Stack method void push(T x) do? - ✔✔ adds x to the top (left end) of this aliases reference x 1 / 2
updates this ensures this =
What does the stack method T pop() do? - ✔✔Removes and retursn the entry at the top (left end of this) updates this requires this /= <> ensures #this =
What does the stack method int length() do? - ✔✔Reports the length of this ensures length = |this|
What does the stack method T top() do? - ✔✔Returns the entry at the top (left end) of this
Aliases: reference returned by top
requires:
this /= <> ensures
What does the stack method T replaceTop(T x) do? - ✔✔replaces top of this with x, and returns the old top aliases reference x updates this requires this /= <>
ensures:
- / 2