Exam 3 Flashcards
is one of the most commonly used data structures in computer science
A stack
The stack’s storage policy is:
Last-In, First Out , or LIFO
boolean empty()
Returns true if the stack is empty; otherwise, returns false.
E peek()
Returns the object at the top of the stack without removing it.
E pop()
Returns the object at the top of stack and removes it.
E push (E obj)
Pushes an item onto the top of the stack and returns the item pushed.
a string that reads identically in either direction , letter by letter (ignoring case )
Palindrome
When analyzing arithmetic expressions, it is important to determine whether an expression is:
balanced with respect to parentheses
The problem is further complicated if braces or brackets are used in ________ with _________.
The solution is to use:
conjunction
parentheses
Stacks
PITFALL: attempting to pop an empty stack will throw an ______________ . You can guard against this by either:
EmptyStackexception
testing for an empty stack or catching the exception
Stacks are so common in computing, that Java included a Stack class in its early versions :
import java.util.Stack;
BUT, the Java Stack class extends Vector (a deprecated class which extends AbstractList) ... THEREFORE the class provides methods \_\_\_\_\_\_\_ to Stacks Its use is:
not traditional
no longer recommended
like the stack, is a widely used data structure
The queue
A queue differs from a stack in one important way:
stack is a LIFO list Last-In, First-Out
while a queue a is FIFO list - First-In, First -Out
Operating systems use queues to:
Keep track of tasks waiting for a scarce resource
ensure that the tasks are carried out in FIFO order