Add a basic Queue data structure
Implemented as a linked list.
This commit is contained in:
parent
4e4b6b9bca
commit
47df42c8e5
4 changed files with 117 additions and 4 deletions
|
|
@ -222,11 +222,11 @@ public class DiamondSquareGenerator: TerrainGenerator {
|
|||
}
|
||||
|
||||
func breadthFirstSearch(visit: (Box) -> (Void)) {
|
||||
var queue = [self]
|
||||
while queue.count > 0 {
|
||||
let box = queue.removeFirst()
|
||||
var queue = Queue<Box>()
|
||||
queue.enqueue(item: self)
|
||||
while let box = queue.dequeue() {
|
||||
visit(box)
|
||||
queue.append(contentsOf: box.subdivisions)
|
||||
queue.enqueue(items: box.subdivisions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue