Skip to content

Commit efe956a

Browse files
committed
Replace animation with my own
The original was apparently taken from Wikipedia and I don't know if we had the rights to it. Besides, it was ugly.
1 parent 784023d commit efe956a

File tree

15 files changed

+69
-60
lines changed

15 files changed

+69
-60
lines changed

Breadth-First Search/BreadthFirstSearch.playground/Pages/Minimum spanning tree example.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph
1010
queue.enqueue(sourceInMinimumSpanningTree)
1111
sourceInMinimumSpanningTree.visited = true
1212

13-
while !queue.isEmpty {
14-
let current = queue.dequeue()!
13+
while let current = queue.dequeue() {
1514
for edge in current.neighbors {
1615
let neighborNode = edge.neighbor
1716
if !neighborNode.visited {
@@ -26,10 +25,12 @@ func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph
2625
return minimumSpanningTree
2726
}
2827

28+
2929
/*:
3030
![Animated example of a breadth-first search](Minimum_Spanning_Tree.png)
3131
*/
3232

33+
3334
let graph = Graph()
3435

3536
let nodeA = graph.addNode("a")

Breadth-First Search/BreadthFirstSearch.playground/Pages/Shortest path example.xcplaygroundpage/Contents.swift

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ func breadthFirstSearchShortestPath(graph: Graph, source: Node) -> Graph {
1010
queue.enqueue(sourceInShortestPathsGraph)
1111
sourceInShortestPathsGraph.distance = 0
1212

13-
while !queue.isEmpty {
14-
let current = queue.dequeue()!
13+
while let current = queue.dequeue() {
1514
for edge in current.neighbors {
1615
let neighborNode = edge.neighbor
1716
if !neighborNode.hasDistance {
@@ -23,9 +22,8 @@ func breadthFirstSearchShortestPath(graph: Graph, source: Node) -> Graph {
2322

2423
return shortestPathGraph
2524
}
26-
/*:
27-
![Animated example of a breadth-first search](Animated_BFS.gif)
28-
*/
25+
26+
2927

3028
let graph = Graph()
3129

Breadth-First Search/BreadthFirstSearch.playground/Pages/Simple example.xcplaygroundpage/Contents.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ func breadthFirstSearch(graph: Graph, source: Node) -> [String] {
77
var nodesExplored = [source.label]
88
source.visited = true
99

10-
while !queue.isEmpty {
11-
let current = queue.dequeue()!
12-
for edge in current.neighbors {
10+
while let node = queue.dequeue() {
11+
for edge in node.neighbors {
1312
let neighborNode = edge.neighbor
1413
if !neighborNode.visited {
1514
queue.enqueue(neighborNode)
@@ -22,9 +21,7 @@ func breadthFirstSearch(graph: Graph, source: Node) -> [String] {
2221
return nodesExplored
2322
}
2423

25-
/*:
26-
![Animated example of a breadth-first search](Animated_BFS.gif)
27-
*/
24+
2825

2926
let graph = Graph()
3027

@@ -44,10 +41,11 @@ graph.addEdge(nodeB, neighbor: nodeE)
4441
graph.addEdge(nodeC, neighbor: nodeF)
4542
graph.addEdge(nodeC, neighbor: nodeG)
4643
graph.addEdge(nodeE, neighbor: nodeH)
44+
graph.addEdge(nodeE, neighbor: nodeF)
45+
graph.addEdge(nodeF, neighbor: nodeG)
4746

4847

4948
let nodesExplored = breadthFirstSearch(graph, source: nodeA)
5049
print(nodesExplored)
5150

5251
//: [Next: Shortest Path Example](@next)
53-
Binary file not shown.

Breadth-First Search/BreadthFirstSearch.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ func breadthFirstSearch(graph: Graph, source: Node) -> [String] {
55
var nodesExplored = [source.label]
66
source.visited = true
77

8-
while !queue.isEmpty {
9-
let current = queue.dequeue()!
8+
while let current = queue.dequeue() {
109
for edge in current.neighbors {
1110
let neighborNode = edge.neighbor
1211
if !neighborNode.visited {

Breadth-First Search/BreadthFirstSearchMinimumSpanningTree.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ func breadthFirstSearchMinimumSpanningTree(graph: Graph, source: Node) -> Graph
66
queue.enqueue(sourceInMinimumSpanningTree)
77
sourceInMinimumSpanningTree.visited = true
88

9-
while !queue.isEmpty {
10-
let current = queue.dequeue()!
9+
while let current = queue.dequeue() {
1110
for edge in current.neighbors {
1211
let neighborNode = edge.neighbor
1312
if !neighborNode.visited {

Breadth-First Search/BreadthFirstSearchShortestPath.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ func breadthFirstSearchShortestPath(graph: Graph, source: Node) -> Graph {
66
queue.enqueue(sourceInShortestPathsGraph)
77
sourceInShortestPathsGraph.distance = 0
88

9-
while !queue.isEmpty {
10-
let current = queue.dequeue()!
9+
while let current = queue.dequeue() {
1110
for edge in current.neighbors {
1211
let neighborNode = edge.neighbor
1312
if !neighborNode.hasDistance {
9.49 KB
Loading
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)