Skip to content

Commit c4fbe74

Browse files
committed
update for standardization
1 parent 58ec9cc commit c4fbe74

35 files changed

+462
-456
lines changed

AKS_Primarility_Test/AKS.c

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
#include<stdio.h>
2-
int isprm(long long int n)
1+
#include <stdio.h>
2+
3+
int isprm(long long n)
4+
{
5+
long long i = 5, w = 2;
6+
if (n == 2 || n==3)
7+
return 1;
8+
if(n%2 == 0 || n%3 == 0 || n == 1)
9+
return 0;
10+
while(i*i <= n)
311
{
4-
long long int i=5,w=2;
5-
if(n==2||n==3)
6-
return 1;
7-
if(n%2==0||n%3==0||n==1)
12+
if(n%i == 0)
813
return 0;
9-
while(i*i<=n)
10-
{
11-
if(n%i==0)
12-
return 0;
13-
i+=w;
14-
w=6-w;
15-
}
16-
return 1;
14+
i += w;
15+
w = 6 - w;
1716
}
17+
return 1;
18+
}
19+
1820
int main()
21+
{
22+
int i;
23+
for (i = 1; i <= 100000000; i++)
1924
{
20-
int i;
21-
for(i=1;i<=100000000;i++)
22-
{
23-
if(isprm(i)==1)
24-
printf("%d\n",i);
25-
}
26-
return 0;
25+
if(isprm(i) == 1)
26+
printf("%d\n",i);
27+
}
28+
return 0;
2729
}

Activity_Selection/Activity_Selection.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
void print_activities(int start[], int finish[], int n)
44
{
5-
printf("%s", "Following activities are selected");
5+
printf("Following activities are selected");
66
int i = 0;
77
printf("\n%d ", i);
88
int j;

Activity_Selection/Activity_Selection.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ func activitySelection(startTime []int, finishTime []int) {
1010
// second step is to print first activity from sorted activity
1111
fmt.Println("activity 1")
1212
// do following in sorted activities:
13-
// If the start time of this activity is greater than the finish time of previously selected activity then select this activity and print it
13+
// If the start time of this activity is greater than the finish time of previously
14+
// selected activity then select this activity and print it
1415
preSelected := 0
1516
for i := 1; i < len(finishTime); i++ {
1617
if startTime[i] > finishTime[preSelected] {
@@ -19,8 +20,10 @@ func activitySelection(startTime []int, finishTime []int) {
1920
}
2021
}
2122
}
23+
2224
func main() {
23-
// first step is to sort activities by finish time, in order to save time, we use an sorted finishTime array
25+
// first step is to sort activities by finish time, in order to save time,
26+
// we use an sorted finishTime array
2427
startTime := []int{1, 3, 1, 5, 8, 6}
2528
finishTime := []int{2, 6, 6, 7, 10, 8}
2629
activitySelection(startTime, finishTime)

Activity_Selection/Activity_Selection.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,20 @@
44

55
class activity_selection
66
{
7-
static void activities(int start[], int finish[], int n)
7+
public static void activities(int start[], int finish[], int n)
88
{
99
int i = 0, j;
1010
System.out.print((i + 1) + " ");
11-
for(j = 1; j < n; j++)
11+
for (j = 1; j < n; j++)
1212
{
13-
if(start[j] >= finish[i])
13+
if (start[j] >= finish[i])
1414
{
1515
System.out.print((j + 1) + " ");
1616
i = j;
1717
}
1818
}
1919
}
20+
2021
public static void main(String args[])
2122
{
2223
int start[] = {1, 3, 1, 5, 8, 6};

Bellmanford_Algorithm/Bellmanford.cpp

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ void bellmanford(int adjacency_matrix[vertices][vertices], int source)
2222
{
2323
for (int k = 0; k < vertices; k++)
2424
{
25-
if (adjacency_matrix[j][k] != 0)
25+
if (adjacency_matrix[j][k] != 0 && distance[j] + adjacency_matrix[j][k] < distance[k])
2626
{
27-
if (distance[j] + adjacency_matrix[j][k] < distance[k])
28-
{
29-
distance[k] = distance[j] + adjacency_matrix[j][k];
30-
predecessor[k] = j;
31-
}
27+
distance[k] = distance[j] + adjacency_matrix[j][k];
28+
predecessor[k] = j;
3229
}
3330
}
3431
}
@@ -50,9 +47,7 @@ void bellmanford(int adjacency_matrix[vertices][vertices], int source)
5047
cout << "Vertex\tDistance\tpredecessor\n";
5148

5249
for (int i = 0; i < vertices; i++)
53-
{
5450
cout << i << "\t" << distance[i] << "\t\t" << predecessor[i] << endl;
55-
}
5651
}
5752

5853
int main()

0 commit comments

Comments
 (0)