Skip to content

Commit 08cf693

Browse files
committed
Fixed Indent issue
1 parent 4f4b09d commit 08cf693

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

Depth-First Search/DepthFirstSearch.playground/Pages/Simple Example.xcplaygroundpage/Contents.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ print("Hello, Swift 4!")
55
#endif
66

77
func depthFirstSearch(_ graph: Graph, source: Node) -> [String] {
8-
var nodesExplored = [source.label]
9-
source.visited = true
10-
11-
for edge in source.neighbors {
12-
if !edge.neighbor.visited {
13-
nodesExplored += depthFirstSearch(graph, source: edge.neighbor)
8+
var nodesExplored = [source.label]
9+
source.visited = true
10+
11+
for edge in source.neighbors {
12+
if !edge.neighbor.visited {
13+
nodesExplored += depthFirstSearch(graph, source: edge.neighbor)
14+
}
1415
}
15-
}
16-
return nodesExplored
16+
return nodesExplored
1717
}
1818

1919
let graph = Graph()
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
public class Edge: Equatable {
2-
public var neighbor: Node
3-
4-
public init(_ neighbor: Node) {
5-
self.neighbor = neighbor
6-
}
2+
public var neighbor: Node
3+
4+
public init(_ neighbor: Node) {
5+
self.neighbor = neighbor
6+
}
77
}
88

99
public func == (_ lhs: Edge, rhs: Edge) -> Bool {
10-
return lhs.neighbor == rhs.neighbor
10+
return lhs.neighbor == rhs.neighbor
1111
}

Depth-First Search/DepthFirstSearch.playground/Sources/Graph.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,51 @@
11
public class Graph: CustomStringConvertible, Equatable {
22
public private(set) var nodes: [Node]
3-
3+
44
public init() {
55
self.nodes = []
66
}
7-
7+
88
public func addNode(_ label: String) -> Node {
99
let node = Node(label)
1010
nodes.append(node)
1111
return node
1212
}
13-
13+
1414
public func addEdge(_ source: Node, neighbor: Node) {
1515
let edge = Edge(neighbor)
1616
source.neighbors.append(edge)
1717
}
18-
18+
1919
public var description: String {
2020
var description = ""
21-
21+
2222
for node in nodes {
2323
if !node.neighbors.isEmpty {
2424
description += "[node: \(node.label) edges: \(node.neighbors.map { $0.neighbor.label})]"
2525
}
2626
}
2727
return description
2828
}
29-
29+
3030
public func findNodeWithLabel(_ label: String) -> Node {
3131
return nodes.filter { $0.label == label }.first!
3232
}
33-
33+
3434
public func duplicate() -> Graph {
3535
let duplicated = Graph()
36-
36+
3737
for node in nodes {
3838
duplicated.addNode(node.label)
3939
}
40-
40+
4141
for node in nodes {
4242
for edge in node.neighbors {
4343
let source = duplicated.findNodeWithLabel(node.label)
4444
let neighbour = duplicated.findNodeWithLabel(edge.neighbor.label)
4545
duplicated.addEdge(source, neighbor: neighbour)
4646
}
4747
}
48-
48+
4949
return duplicated
5050
}
5151
}

Depth-First Search/DepthFirstSearch.playground/Sources/Node.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
public class Node: CustomStringConvertible, Equatable {
22
public var neighbors: [Edge]
3-
3+
44
public private(set) var label: String
55
public var distance: Int?
66
public var visited: Bool
7-
7+
88
public init(_ label: String) {
99
self.label = label
1010
neighbors = []
1111
visited = false
1212
}
13-
13+
1414
public var description: String {
1515
if let distance = distance {
1616
return "Node(label: \(label), distance: \(distance))"
1717
}
1818
return "Node(label: \(label), distance: infinity)"
1919
}
20-
20+
2121
public var hasDistance: Bool {
2222
return distance != nil
2323
}
24-
24+
2525
public func remove(_ edge: Edge) {
2626
neighbors.remove(at: neighbors.index { $0 === edge }!)
2727
}

0 commit comments

Comments
 (0)