Implementing Stacks and Queues

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

1/10

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.

11 Terms

1
New cards

What is used to design and implement the Stack class?

An ArrayList

2
New cards

What is used to design and implement the Queue class?

A LinkedList

3
New cards

What is used to design and implement a Priority Queue?

A heap

4
New cards

What is a Stack?

A special type of list, where the elements are accessed, inserted, and deleted only from the end, called the top of the stack.

5
New cards

Why is an ArrayList used to implement a Stack rather than a LinkedList?

Since the insertion and deletion operations on a Stack are made only at the end of the Stack

6
New cards

In what two ways can the Stack class be designed?

Using inheritance - Define the Stack class by extending the ArrayList class

Using composition - Define an ArrayList as a data field in the Stack class

7
New cards

What is a Queue?

A special type of list, where the elements are inserted at the end (tail) of the queue, and are accessed and deleted from the beginning (head) of the queue.

8
New cards

Why is a LinkedList used to implement a Queue rather than an ArrayList?

Since deletions are made at the beginning of the List.

9
New cards

In what two ways can the Queue class be designed?

Using inheritance - Define the Queue class by extending the LinkedList class

Using composition - Define a LinkedList as a data field in the Queue class

10
New cards

Why is composition better for designing Stacks and Queues?

It enables you to define a complete new Stack class and Queue class without inheriting the unnecessary and inappropriate methods from the ArrayList and LinkedList

11
New cards

What is the difference between Queue and Priority Queue?

- A regular Queue is First-In-First-Out behavior

- In a Priority Queue, elements have an assigned priority. Elements with a higher priority are removed from the Queue first. Priority Queue has Largest-In, First-Out behavior.