CSE 2221 Final Exam |Questions with Correct Answers| Verified|
Latest update 2025/2026
Why is the container class called Stack? - Answer✔✔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 - Answer✔✔last in first out
How is a Stack different than the queue? - Answer✔✔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? - Answer✔✔push
pop
length
What are the three methods of the Stack Interface? - Answer✔✔top
replaceTop
flip
What mathematical model is Stack modeled by? - Answer✔✔Modeled by mathematical
string of T
How many constructors for Stack? - Answer✔✔only 1, which is empty, creates an empty
stack
What does the Stack method void push(T x) do? - Answer✔✔adds x to the top (left end) of
this
aliases reference x
updates this
ensures
this = <x> * #this
, What does the stack method T pop() do? - Answer✔✔Removes and retursn the entry at the
top (left end of this)
updates this
requires this /= <>
ensures
#this = <pop> * this
What does the stack method int length() do? - Answer✔✔Reports the length of this
ensures
length = |this|
What does the stack method T top() do? - Answer✔✔Returns the entry at the top (left end)
of this
Aliases: reference returned by top
requires:
this /= <>
ensures
<top> is prefix of this
What does the stack method T replaceTop(T x) do? - Answer✔✔replaces top of this with x,
and returns the old top
aliases reference x
updates this
requires
this /= <>
ensures:
<replaceTop> is prefix of #this and
this = <x> * #this[1, |#this|)
Latest update 2025/2026
Why is the container class called Stack? - Answer✔✔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 - Answer✔✔last in first out
How is a Stack different than the queue? - Answer✔✔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? - Answer✔✔push
pop
length
What are the three methods of the Stack Interface? - Answer✔✔top
replaceTop
flip
What mathematical model is Stack modeled by? - Answer✔✔Modeled by mathematical
string of T
How many constructors for Stack? - Answer✔✔only 1, which is empty, creates an empty
stack
What does the Stack method void push(T x) do? - Answer✔✔adds x to the top (left end) of
this
aliases reference x
updates this
ensures
this = <x> * #this
, What does the stack method T pop() do? - Answer✔✔Removes and retursn the entry at the
top (left end of this)
updates this
requires this /= <>
ensures
#this = <pop> * this
What does the stack method int length() do? - Answer✔✔Reports the length of this
ensures
length = |this|
What does the stack method T top() do? - Answer✔✔Returns the entry at the top (left end)
of this
Aliases: reference returned by top
requires:
this /= <>
ensures
<top> is prefix of this
What does the stack method T replaceTop(T x) do? - Answer✔✔replaces top of this with x,
and returns the old top
aliases reference x
updates this
requires
this /= <>
ensures:
<replaceTop> is prefix of #this and
this = <x> * #this[1, |#this|)