@@ -4,15 +4,14 @@ package com.lillicoder.algorithms.graphs
4
4
* Interface for implementations of a [Graph](https://en.wikipedia.org/wiki/Graph_(abstract_data_type)).
5
5
*/
6
6
interface Graph <T > : Iterable <T > {
7
-
8
7
/* *
9
8
* Implementation of an [Iterator] for a [Graph] that uses [Traversal.BREADTH_FIRST] order.
10
9
* @param graph Graph to traverse.
11
10
*/
12
11
private class BreadthFirstIterator <T >(
13
12
private val graph : Graph <T >,
14
13
root : T = graph.root(),
15
- ): Iterator<T> {
14
+ ) : Iterator<T> {
16
15
private val queue = ArrayDeque (listOf (root))
17
16
private val visited = mutableMapOf (root to true )
18
17
@@ -65,7 +64,10 @@ interface Graph<T> : Iterable<T> {
65
64
* @param first First element.
66
65
* @param second Second element.
67
66
*/
68
- fun addEdge (first : T , second : T )
67
+ fun addEdge (
68
+ first : T ,
69
+ second : T ,
70
+ )
69
71
70
72
/* *
71
73
* Adds the given element to this graph.
@@ -79,7 +81,10 @@ interface Graph<T> : Iterable<T> {
79
81
* @param second Second element.
80
82
* @return True if there is an edge between the elements, false otherwise.
81
83
*/
82
- fun adjacent (first : T , second : T ): Boolean
84
+ fun adjacent (
85
+ first : T ,
86
+ second : T ,
87
+ ): Boolean
83
88
84
89
/* *
85
90
* Determines if this graph contains the given element.
@@ -115,7 +120,10 @@ interface Graph<T> : Iterable<T> {
115
120
* @param first First element.
116
121
* @param second Second element.
117
122
*/
118
- fun removeEdge (first : T , second : T )
123
+ fun removeEdge (
124
+ first : T ,
125
+ second : T ,
126
+ )
119
127
120
128
/* *
121
129
* Removes the given element from this graph.
0 commit comments