---
tags: Setup
---
# Lecture 25 Setup/Prep
(was spring 2021 Lecture 24)
Last class, we talked about two approaches to implementing heaps:
1. implementing doubly-linked trees with classes for nodes and leaves,
2. implementing doubly-linked trees with arrays.
This class, we're going to discuss these further, then talk about how heaps are useful in sorting.
We'll then return to managing `Alert` priorities: we'll learn about *Priority Queues*, a built-in data structure in Scala (and many other languages) that uses heaps to manage priorities.
We will also talk a bit about a separate topic: manipulating data structures stored within arrays.
## Prep
Think about the following questions, which you will discuss in breakouts at the start of lecture:
- Which is more efficient in terms of running-time?
- What is the space usage of each?
- Which approach do you prefer? Why?
**New Wednesday Morning** -- starter code sample
```
package lec24
import scala.collection.mutable.PriorityQueue
// -------- Alerts --------------
class Alert(val username: String, val descr: String, val severity: Int) {}
object Main extends App {
// Make/manage a heap of numbers
val numHeap = new PriorityQueue[Integer]
// add items
numHeap.enqueue(6)
numHeap.enqueue(1)
numHeap.enqueue(3)
numHeap.enqueue(8)
println("the heap contains: " + numHeap)
// look at max item
println("the top value is: " + numHeap.head)
println("the heap contains: " + numHeap)
// remove and return max item
val max = numHeap.dequeue()
println("the max was: " + max)
println("the heap contains: " + numHeap)
}
```