Skip to content

Commit 2f5baf0

Browse files
committed
remove redundant "else" / "else if"
1 parent 4d0f093 commit 2f5baf0

40 files changed

+295
-363
lines changed

Algorithms/Graphs/BellmanFordShortestPaths.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public BellmanFordShortestPaths(TGraph Graph, TVertex Source)
3737
{
3838
if (Graph == null)
3939
throw new ArgumentNullException();
40-
else if (!Graph.HasVertex(Source))
40+
if (!Graph.HasVertex(Source))
4141
throw new ArgumentException("The source vertex doesn't belong to graph.");
4242

4343
// Init
@@ -252,7 +252,7 @@ public IEnumerable<TVertex> ShortestPathTo(TVertex destination)
252252
{
253253
if (!_nodesToIndices.ContainsKey(destination))
254254
throw new Exception("Graph doesn't have the specified vertex.");
255-
else if (!HasPathTo(destination))
255+
if (!HasPathTo(destination))
256256
return null;
257257

258258
int dstIndex = _nodesToIndices[destination];

Algorithms/Graphs/BipartiteColoring.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public BipartiteColoring(IGraph<TVertex> Graph)
5757
// Validate Graph parameter
5858
if (Graph == null)
5959
throw new ArgumentNullException();
60-
else if (Graph.VerticesCount < 2)
60+
if (Graph.VerticesCount < 2)
6161
throw new InvalidOperationException("Graph contains less elements than required.");
6262

6363
// Init data members
@@ -177,7 +177,7 @@ public BipartiteColor ColorOf(TVertex vertex)
177177
{
178178
if (!_isBipartite)
179179
throw new InvalidOperationException("Graph is not bipartite.");
180-
else if (!_nodesToIndices.ContainsKey(vertex))
180+
if (!_nodesToIndices.ContainsKey(vertex))
181181
throw new InvalidOperationException("Vertex doesn't belong to graph.");
182182

183183
return _nodesColors[_nodesToIndices[vertex]];

Algorithms/Graphs/BreadthFirstShortestPaths.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public BreadthFirstShortestPaths(IGraph<T> Graph, T Source)
3838
{
3939
if (Graph == null)
4040
throw new ArgumentNullException();
41-
else if (!Graph.HasVertex(Source))
41+
if (!Graph.HasVertex(Source))
4242
throw new ArgumentException("The source vertex doesn't belong to graph.");
4343

4444
// Init
@@ -60,7 +60,7 @@ public BreadthFirstShortestPaths(IGraph<T> Graph, IList<T> Sources)
6060
{
6161
if (Graph == null)
6262
throw new ArgumentNullException();
63-
else if (Sources == null || Sources.Count == 0)
63+
if (Sources == null || Sources.Count == 0)
6464
throw new ArgumentException("Sources list is either null or empty.");
6565

6666
// Init
@@ -281,7 +281,7 @@ public IEnumerable<T> ShortestPathTo(T destination)
281281
{
282282
if (!_nodesToIndices.ContainsKey(destination))
283283
throw new Exception("Graph doesn't have the specified vertex.");
284-
else if (!HasPathTo(destination))
284+
if (!HasPathTo(destination))
285285
return null;
286286

287287
int dstIndex = _nodesToIndices[destination];

Algorithms/Graphs/ConnectedComponents.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public static List<List<TVertex>> Compute<TVertex>(IGraph<TVertex> Graph) where
5656
// Validate the graph parameter
5757
if (Graph == null)
5858
throw new ArgumentNullException();
59-
else if (Graph.IsDirected == true)
59+
if (Graph.IsDirected == true)
6060
throw new NotSupportedException("Directed Graphs are not supported.");
61-
else if(Graph.VerticesCount == 0)
61+
if(Graph.VerticesCount == 0)
6262
return components;
6363

6464
// Get connected components using BFS

Algorithms/Graphs/CyclesDetector.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ private static bool _isUndirectedCyclic<T>(IGraph<T> graph, T source, object par
3838
return true;
3939

4040
// If an adjacent is visited and NOT parent of current vertex, then there is a cycle.
41-
else if (parent != (object)null && !adjacent.IsEqualTo((T)parent))
41+
if (parent != (object)null && !adjacent.IsEqualTo((T)parent))
4242
return true;
4343
}
4444
}
@@ -72,7 +72,7 @@ private static bool _isDirectedCyclic<T>(IGraph<T> graph, T source, ref HashSet<
7272
return true;
7373

7474
// If an adjacent is visited and is on the recursion stack then there is a cycle.
75-
else if (recursionStack.Contains(adjacent))
75+
if (recursionStack.Contains(adjacent))
7676
return true;
7777
}
7878
}

Algorithms/Graphs/DijkstraShortestPaths.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ public IEnumerable<TVertex> ShortestPathTo(TVertex destination)
282282
{
283283
throw new Exception("Graph doesn't have the specified vertex.");
284284
}
285-
else if (!HasPathTo(destination))
285+
286+
if (!HasPathTo(destination))
286287
{
287288
return null;
288289
}

Algorithms/Graphs/TopologicalSorter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static IEnumerable<T> Sort<T>(IGraph<T> Graph) where T : IComparable<T>
3434
// If the graph is either null or is not a DAG, throw exception.
3535
if (Graph == null)
3636
throw new ArgumentNullException();
37-
else if (!Graph.IsDirected || CyclesDetector.IsCyclic<T>(Graph))
37+
if (!Graph.IsDirected || CyclesDetector.IsCyclic<T>(Graph))
3838
throw new Exception("The graph is not a DAG.");
3939

4040
var visited = new HashSet<T>();

Algorithms/Numeric/GreatestCommonDivisor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static uint FindGCD(uint a, uint b)
1515
{
1616
if (a == 0)
1717
return b;
18-
else if (b == 0)
18+
if (b == 0)
1919
return a;
2020

2121
uint _a = a, _b = b;

Algorithms/Sorting/LSDRadixSorter.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,9 @@ public static void LSDRadixSort(this IList<String> collection, int stringFixedWi
6969
// Validate input
7070
if (collection == null || collection.Count <= 1)
7171
return;
72-
else
73-
{
74-
for (int i = 0; i < collection.Count; ++i)
75-
if (collection[i] == null || collection[i].Length != stringFixedWidth)
76-
throw new InvalidOperationException("Not all strings have the same width");
77-
}
72+
for (int i = 0; i < collection.Count; ++i)
73+
if (collection[i] == null || collection[i].Length != stringFixedWidth)
74+
throw new InvalidOperationException("Not all strings have the same width");
7875

7976
// extend ASCII alphabet size
8077
int asciiSize = 256;

Algorithms/Sorting/MergeSorter.cs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ private static List<T> InternalMergeSort<T>(List<T> collection, int startIndex,
2424
{
2525
return collection;
2626
}
27-
else if (collection.Count == 2)
27+
28+
if (collection.Count == 2)
2829
{
2930
if (comparer.Compare(collection[endIndex], collection[startIndex]) < 0)
3031
{
@@ -33,18 +34,16 @@ private static List<T> InternalMergeSort<T>(List<T> collection, int startIndex,
3334

3435
return collection;
3536
}
36-
else
37-
{
38-
int midIndex = collection.Count / 2;
3937

40-
var leftCollection = collection.GetRange(startIndex, midIndex);
41-
var rightCollection = collection.GetRange(midIndex, (endIndex - midIndex) + 1);
38+
int midIndex = collection.Count / 2;
4239

43-
leftCollection = InternalMergeSort<T>(leftCollection, 0, leftCollection.Count - 1, comparer);
44-
rightCollection = InternalMergeSort<T>(rightCollection, 0, rightCollection.Count - 1, comparer);
40+
var leftCollection = collection.GetRange(startIndex, midIndex);
41+
var rightCollection = collection.GetRange(midIndex, (endIndex - midIndex) + 1);
4542

46-
return InternalMerge<T>(leftCollection, rightCollection, comparer);
47-
}
43+
leftCollection = InternalMergeSort<T>(leftCollection, 0, leftCollection.Count - 1, comparer);
44+
rightCollection = InternalMergeSort<T>(rightCollection, 0, rightCollection.Count - 1, comparer);
45+
46+
return InternalMerge<T>(leftCollection, rightCollection, comparer);
4847
}
4948

5049

0 commit comments

Comments
 (0)