Skip to content

Commit

Permalink
- Fixing some JetBrains ReSharper warnings, thanks for their Open Sou…
Browse files Browse the repository at this point in the history
…rce license :)
  • Loading branch information
mina-asham committed May 13, 2015
1 parent abe80ff commit bb90edc
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 36 deletions.
4 changes: 2 additions & 2 deletions algs4/algs4/Alphabet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Alphabet
public Alphabet(string alpha)
{
// check that alphabet contains no duplicate chars
bool[] unicode = new bool[Char.MaxValue];
bool[] unicode = new bool[char.MaxValue];
for (int i = 0; i < alpha.Length; i++)
{
char c = alpha[i];
Expand All @@ -56,7 +56,7 @@ public Alphabet(string alpha)

_alphabet = alpha.ToCharArray();
_r = alpha.Length;
_inverse = new int[Char.MaxValue];
_inverse = new int[char.MaxValue];
for (int i = 0; i < _inverse.Length; i++)
{
_inverse[i] = -1;
Expand Down
42 changes: 21 additions & 21 deletions algs4/algs4/Bipartite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ public IEnumerable<int> OddCycle()
return _cycle;
}

private bool Check(Graph G)
private bool Check(Graph g)
{
// graph is bipartite
if (_isBipartite)
{
for (int v = 0; v < G.V(); v++)
for (int v = 0; v < g.V(); v++)
{
foreach (int w in G.Adj(v))
foreach (int w in g.Adj(v))
{
if (_color[v] == _color[w])
{
Expand Down Expand Up @@ -169,42 +169,42 @@ private bool Check(Graph G)
public static void RunMain(string[] args)
{
// create random bipartite graph with V vertices and E edges; then add F random edges
int V = int.Parse(args[0]);
int E = int.Parse(args[1]);
int F = int.Parse(args[2]);
int v = int.Parse(args[0]);
int e = int.Parse(args[1]);
int f = int.Parse(args[2]);

Graph G = new Graph(V);
int[] vertices = new int[V];
for (int i = 0; i < V; i++)
Graph g = new Graph(v);
int[] vertices = new int[v];
for (int i = 0; i < v; i++)
{
vertices[i] = i;
}
StdRandom.Shuffle(vertices);
for (int i = 0; i < E; i++)
for (int i = 0; i < e; i++)
{
int v = StdRandom.Uniform(V / 2);
int w = StdRandom.Uniform(V / 2);
G.AddEdge(vertices[v], vertices[V / 2 + w]);
int vFrom = StdRandom.Uniform(v / 2);
int wTo = StdRandom.Uniform(v / 2);
g.AddEdge(vertices[vFrom], vertices[v / 2 + wTo]);
}

// add F extra edges
Random random = new Random();
for (int i = 0; i < F; i++)
for (int i = 0; i < f; i++)
{
int v = (int)(random.NextDouble() * V);
int w = (int)(random.NextDouble() * V);
G.AddEdge(v, w);
int vFrom = (int)(random.NextDouble() * v);
int wFrom = (int)(random.NextDouble() * v);
g.AddEdge(vFrom, wFrom);
}

StdOut.PrintLn(G);
StdOut.PrintLn(g);

Bipartite b = new Bipartite(G);
Bipartite b = new Bipartite(g);
if (b.IsBipartite())
{
StdOut.PrintLn("Graph is bipartite");
for (int v = 0; v < G.V(); v++)
for (int vertex = 0; vertex < g.V(); vertex++)
{
StdOut.PrintLn(v + ": " + b.Color(v));
StdOut.PrintLn(vertex + ": " + b.Color(vertex));
}
}
else
Expand Down
6 changes: 3 additions & 3 deletions algs4/algs4/CollisionSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ public void Simulate(double limit)
{
a.BounceOff(b); // particle-particle collision
}
else if (a != null && b == null)
else if (a != null)
{
a.BounceOffVerticalWall(); // particle-wall collision
}
else if (a == null && b != null)
else if (b != null)
{
b.BounceOffHorizontalWall(); // particle-wall collision
}
else if (a == null && b == null)
else
{
Redraw(limit); // redraw event
}
Expand Down
2 changes: 1 addition & 1 deletion algs4/algs4/Date.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public override string ToString()
/// </summary>
/// <param name="x"></param>
/// <returns>true if this date equals x; false otherwise</returns>
public override bool Equals(Object x)
public override bool Equals(object x)
{
if (x == this)
{
Expand Down
3 changes: 1 addition & 2 deletions algs4/algs4/DepthFirstDirectedPaths.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using algs4.stdlib;

namespace algs4.algs4
Expand Down
3 changes: 1 addition & 2 deletions algs4/algs4/DepthFirstPaths.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using algs4.stdlib;

namespace algs4.algs4
Expand Down
4 changes: 2 additions & 2 deletions algs4/algs4/DijkstraSP.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class DijkstraSP
/// <summary>
/// Priority queue of vertices
/// </summary>
private readonly IndexMinPQ<Double> _pq;
private readonly IndexMinPQ<double> _pq;

/// <summary>
/// Computes a shortest paths tree from s to every other vertex in
Expand All @@ -47,7 +47,7 @@ public DijkstraSP(EdgeWeightedDigraph g, int s)
_distTo[s] = 0.0;

// relax vertices in order of distance from s
_pq = new IndexMinPQ<Double>(g.V());
_pq = new IndexMinPQ<double>(g.V());
_pq.Insert(s, _distTo[s]);
while (!_pq.IsEmpty())
{
Expand Down
2 changes: 1 addition & 1 deletion algs4/algs4/Point2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public int Compare(Point2D p, Point2D q)
/// </summary>
/// <param name="other">the other point</param>
/// <returns>true if this point equals the other point; false otherwise</returns>
public override bool Equals(Object other)
public override bool Equals(object other)
{
if (other == this)
{
Expand Down
2 changes: 1 addition & 1 deletion algs4/algs4/ThreeSum.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace algs4.algs4
{
public class ThreeSum
public static class ThreeSum
{
/// <summary>
/// Prints to standard output the (i, j, k) with i &lt; j &lt; k such that a[i] + a[j] + a[k] == 0.
Expand Down
2 changes: 1 addition & 1 deletion algs4Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace algs4Console
{
class Program
static class Program
{
/// <summary>
/// Possible templates to extract RunMain methods from, usually class name is the name of the algorithm
Expand Down

0 comments on commit bb90edc

Please sign in to comment.