stacks and queues

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/18

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

19 Terms

1
New cards

Stacks store/retrieve pattern

LIFO

2
New cards

stacks analogy

stack of trays in a cafeteria

  • can only add to top

  • can only remove from top

  • cannot remove from middle

3
New cards

.push();

adds argument element to top of stack

4
New cards

.pop()

retrieves and removes stack’s top element

5
New cards

.peek();

retrieves but does not remove stack’s top element

6
New cards

Stack and queues similarity 1

modularly resizable (like arraylists)

7
New cards

queues store/retrieve pattern

FIFO

8
New cards

queues analogy

line of people

  • add to back

  • remove from front

  • cannot retrieve/remove from middle

9
New cards

.add();

adds argument element to back of queue

10
New cards

.remove();

retrieves and removes queues front element

if empty, throws an exception

11
New cards

.poll();

same as remove, but returns null is queue is empty

12
New cards

.peek();

retrieves but does not remove queues front element

13
New cards

queue java API

interface

14
New cards

Queue instantiation

Which of the following is/are valid?:

#1.) Queue<Student> = new Queue<Student>();

#2.) Queue<Student> = new LinkedList<Student>();

#3.) LinkedList<Student> = new Queue<Student>();

#4.) Student<Queue> = new Student<Queue>();

2

15
New cards

ideal stack and queue time complexity

constant time

16
New cards

could we implement stack using an arraylist?

yes

17
New cards

Could we implement a Queue using an ArrayList?

no

18
New cards

Could we implement a Queue using a LinkedList (w/ front only)?

no

19
New cards

Could we implement a Queue using a LinkedList (w/ front and back)?

yes