Skip to content

Commit 36e0996

Browse files
committed
standardization
1 parent c436565 commit 36e0996

File tree

63 files changed

+445
-445
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+445
-445
lines changed

Fenwick_Tree/Fenwick_Tree.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ int lowbit(int x) {
1010
}
1111

1212
void update(int index, int value) {
13-
// add "value" to the index-th element
13+
// add "value" to the index-th element
1414
for( ; index <= N ; index += lowbit(index)) {
1515
bit[index] += value;
1616
}
@@ -26,7 +26,7 @@ int query(int index) {
2626
}
2727

2828
int main(){
29-
29+
3030
N = 10;
3131

3232
// WARNING: the index of the first element is 1

Fermat_Little_Theorem/Fermat_Little_Theorem.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#include <stdio.h>
22
#include <stdbool.h>
3+
#include <stdlib.h>
34

45
int power(int a, unsigned int n, int p)
56
{
67
int res = 1;
78
a = a % p;
8-
9+
910
while (n>0)
1011
{
1112
if (n & 1)
1213
res = (res*a)%p;
1314
n = n>>1;
1415
a = (a*a) % p;
1516
}
16-
17+
1718
return res;
1819
}
1920

@@ -31,7 +32,7 @@ bool isPrime(unsigned int n, int k)
3132
return false;
3233
k--;
3334
}
34-
35+
3536
return true;
3637
}
3738

Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
#include <iostream>
22
#include <limits.h>
33
#include <iomanip>
4+
45
#define Infinity INT_MAX
56
#define A 4
7+
68
using namespace std;
79

810
void FloydWarshall(int graph[A][A]);
911

1012
void output(int length[A][A]);
1113

12-
1314
void FloydWarshall(int graph[A][A])
14-
{ int length[A][A],x,y,z;
15+
{
16+
int length[A][A],x,y,z;
1517
for(x = 0; x < A; x++)
1618
for(y = 0; y < A; y++)
1719
length[x][y] = graph[x][y];
18-
19-
20+
2021
for(z = 0; z < A; z++)
2122
for(x = 0; x < A; x++)
2223
for(y = 0; y < A; y++)
@@ -26,19 +27,22 @@ void FloydWarshall(int graph[A][A])
2627
length[x][y] = length[x][z] + length[z][y];
2728
}
2829
output(length);
29-
}
30+
}
3031

3132
void output(int length[A][A])
32-
{ cout << "The matrix below shows the shortest distances between each pair of vertices\n";
33+
{
34+
cout << "The matrix below shows the shortest distances between each pair of vertices\n";
3335
for (int x = 0; x < A; x++)
34-
{for (int y = 0; y < A; y++)
35-
{ if (length[x][y] == Infinity)
36+
{
37+
for (int y = 0; y < A; y++)
38+
{
39+
if (length[x][y] == Infinity)
3640
cout << setw(12) << "INFINITY";
3741
else
3842
cout << setw(12) << length[x][y];
3943
}
4044
cout << endl;
41-
}
45+
}
4246
}
4347

4448
int main() {
@@ -47,7 +51,7 @@ int main() {
4751
{Infinity, Infinity, 0, 7},
4852
{Infinity, Infinity, Infinity, 0}
4953
};
50-
FloydWarshall(graph);
54+
FloydWarshall(graph);
5155
return 0;
5256
}
5357

Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package main
2-
2+
33
import (
44
"fmt"
55
"math"
@@ -31,7 +31,7 @@ func floyd_warshall(graph [][]float64) [][]float64 {
3131
}
3232
return dist
3333
}
34-
34+
3535
func main() {
3636
graph := [][]float64{
3737
{0, 5, math.Inf(1), 10},

Floyd_Warshall_Algorithm/Floyd_Warshall_Algorithm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def main():
4444
[float('inf'), float('inf'), 0, 1],
4545
[float('inf'), float('inf'), float('inf'), 0]]
4646

47-
47+
4848
floyd = FloydWarshall(graph)
4949
floyd.run()
5050
floyd.print_distance()

Ford_Fulkerson_Method/Ford_Fulkerson_Method.cpp

+92-91
Original file line numberDiff line numberDiff line change
@@ -3,110 +3,111 @@
33
#include <limits.h>
44
#include <string.h>
55
#include <queue>
6+
67
using namespace std;
7-
 
8+
89
// Number of vertices in given graph
910
#define V 6
10-
 
11+
1112
/* Returns true if there is a path from source 's' to sink 't' in
1213
  residual graph. Also fills parent[] to store the path */
1314
bool bfs(int rGraph[V][V], int s, int t, int parent[])
1415
{
15-
    // Create a visited array and mark all vertices as not visited
16-
    bool visited[V];
17-
    memset(visited, 0, sizeof(visited));
18-
 
19-
    // Create a queue, enqueue source vertex and mark source vertex
20-
    // as visited
21-
    queue <int> q;
22-
    q.push(s);
23-
    visited[s] = true;
24-
    parent[s] = -1;
25-
 
26-
    // Standard BFS Loop
27-
    while (!q.empty())
28-
    {
29-
        int u = q.front();
30-
        q.pop();
31-
 
32-
        for (int v=0; v<V; v++)
33-
        {
34-
            if (visited[v]==false && rGraph[u][v] > 0)
35-
            {
36-
                q.push(v);
37-
                parent[v] = u;
38-
                visited[v] = true;
39-
            }
40-
        }
41-
    }
42-
 
43-
    // If we reached sink in BFS starting from source, then return
44-
    // true, else false
45-
    return (visited[t] == true);
16+
// Create a visited array and mark all vertices as not visited
17+
bool visited[V];
18+
memset(visited, 0, sizeof(visited));
19+
20+
// Create a queue, enqueue source vertex and mark source vertex
21+
// as visited
22+
queue <int> q;
23+
q.push(s);
24+
visited[s] = true;
25+
parent[s] = -1;
26+
27+
// Standard BFS Loop
28+
while (!q.empty())
29+
{
30+
int u = q.front();
31+
q.pop();
32+
33+
for (int v = 0; v < V; v++)
34+
{
35+
if (visited[v]==false && rGraph[u][v] > 0)
36+
{
37+
q.push(v);
38+
parent[v] = u;
39+
visited[v] = true;
40+
}
41+
}
42+
}
43+
44+
// If we reached sink in BFS starting from source, then return
45+
// true, else false
46+
return (visited[t] == true);
4647
}
47-
 
48+
4849
// Returns tne maximum flow from s to t in the given graph
4950
int fordFulkerson(int graph[V][V], int s, int t)
5051
{
51-
    int u, v;
52-
 
53-
    // Create a residual graph and fill the residual graph with
54-
    // given capacities in the original graph as residual capacities
55-
    // in residual graph
56-
    int rGraph[V][V]; // Residual graph where rGraph[i][j] indicates
57-
                     // residual capacity of edge from i to j (if there
58-
                     // is an edge. If rGraph[i][j] is 0, then there is not) 
59-
    for (u = 0; u < V; u++)
60-
        for (v = 0; v < V; v++)
61-
             rGraph[u][v] = graph[u][v];
62-
 
63-
    int parent[V];  // This array is filled by BFS and to store path
64-
 
65-
    int max_flow = 0;  // There is no flow initially
66-
 
67-
    // Augment the flow while tere is path from source to sink
68-
    while (bfs(rGraph, s, t, parent))
69-
    {
70-
        // Find minimum residual capacity of the edhes along the
71-
        // path filled by BFS. Or we can say find the maximum flow
72-
        // through the path found.
73-
        int path_flow = INT_MAX;
74-
        for (v=t; v!=s; v=parent[v])
75-
        {
76-
            u = parent[v];
77-
            path_flow = min(path_flow, rGraph[u][v]);
78-
        }
79-
 
80-
        // update residual capacities of the edges and reverse edges
81-
        // along the path
82-
        for (v=t; v != s; v=parent[v])
83-
        {
84-
            u = parent[v];
85-
            rGraph[u][v] -= path_flow;
86-
            rGraph[v][u] += path_flow;
87-
        }
88-
 
89-
        // Add path flow to overall flow
90-
        max_flow += path_flow;
91-
    }
92-
 
93-
    // Return the overall flow
94-
    return max_flow;
52+
int u, v;
53+
54+
// Create a residual graph and fill the residual graph with
55+
// given capacities in the original graph as residual capacities
56+
// in residual graph
57+
int rGraph[V][V]; // Residual graph where rGraph[i][j] indicates
58+
// residual capacity of edge from i to j (if there
59+
// is an edge. If rGraph[i][j] is 0, then there is not) 
60+
for (u = 0; u < V; u++)
61+
for (v = 0; v < V; v++)
62+
rGraph[u][v] = graph[u][v];
63+
64+
int parent[V];//This array is filled by BFS and to store path
65+
66+
int max_flow = 0;//There is no flow initially
67+
68+
// Augment the flow while tere is path from source to sink
69+
while (bfs(rGraph, s, t, parent))
70+
{
71+
// Find minimum residual capacity of the edhes along the
72+
// path filled by BFS. Or we can say find the maximum flow
73+
// through the path found.
74+
int path_flow = INT_MAX;
75+
for (v=t; v!=s; v=parent[v])
76+
{
77+
u = parent[v];
78+
path_flow = min(path_flow, rGraph[u][v]);
79+
}
80+
81+
// update residual capacities of the edges and reverse edges
82+
// along the path
83+
for (v=t; v != s; v=parent[v])
84+
{
85+
u = parent[v];
86+
rGraph[u][v] -= path_flow;
87+
rGraph[v][u] += path_flow;
88+
}
89+
90+
// Add path flow to overall flow
91+
max_flow += path_flow;
92+
}
93+
94+
// Return the overall flow
95+
return max_flow;
9596
}
96-
 
97+
9798
// Driver program to test above functions
9899
int main()
99100
{
100-
    // Let us create a graph shown in the above example
101-
    int graph[V][V] = { {0, 16, 13, 0, 0, 0},
102-
                        {0, 0, 10, 12, 0, 0},
103-
                        {0, 4, 0, 0, 14, 0},
104-
                        {0, 0, 9, 0, 0, 20},
105-
                        {0, 0, 0, 7, 0, 4},
106-
                        {0, 0, 0, 0, 0, 0}
107-
                      };
108-
 
109-
    cout << "The maximum possible flow is " << fordFulkerson(graph, 0, 5);
110-
 
111-
    return 0;
101+
// Let us create a graph shown in the above example
102+
int graph[V][V] = { {0, 16, 13, 0, 0, 0},
103+
{0, 0, 10, 12, 0, 0},
104+
{0, 4, 0, 0, 14, 0},
105+
{0, 0, 9, 0, 0, 20},
106+
{0, 0, 0, 7, 0, 4},
107+
{0, 0, 0, 0, 0, 0}
108+
};
109+
110+
cout << "The maximum possible flow is " << fordFulkerson(graph, 0, 5);
111+
112+
return 0;
112113
}

Ford_Fulkerson_Method/Ford_Fulkerson_Method.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55

66
class Ford_Fulkerson_Method {
7-
7+
88
//Number of vertices in graph
99
static final int V = 6;
10-
10+
1111
/* Returns true if there is a path from source 's' to sink
1212
't' in residual graph. Also fills parent[] to store the
1313
path */
@@ -118,7 +118,7 @@ public static void main (String[] args) throws java.lang.Exception
118118
m.fordFulkerson(graph, 0, 5));
119119

120120
}
121-
121+
122122

123123
}
124124
/* Output
@@ -127,4 +127,4 @@ public static void main (String[] args) throws java.lang.Exception
127127
128128
129129
130-
*/
130+
*/

0 commit comments

Comments
 (0)