Skip to content

Commit 7b053dc

Browse files
authored
Merge branch 'master' into Temperature-Conversion-issue#5042
2 parents ed22de7 + da21ffe commit 7b053dc

21 files changed

+287
-347
lines changed

.github/dependabot.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
version: 2
3+
updates:
4+
- package-ecosystem: "docker"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
9+
- package-ecosystem: "github-actions"
10+
directory: "/.github/workflows/"
11+
schedule:
12+
interval: "daily"
13+
...

.github/workflows/build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
steps:
77
- uses: actions/checkout@v4
88
- name: Set up JDK 17
9-
uses: actions/setup-java@v3
9+
uses: actions/setup-java@v4
1010
with:
1111
java-version: 17
1212
distribution: 'adopt'

.github/workflows/codeql.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,21 @@ jobs:
2727
uses: actions/checkout@v4
2828

2929
- name: Set up JDK 17
30-
uses: actions/setup-java@v3
30+
uses: actions/setup-java@v4
3131
with:
3232
java-version: 17
3333
distribution: 'adopt'
3434

3535
- name: Initialize CodeQL
36-
uses: github/codeql-action/init@v2
36+
uses: github/codeql-action/init@v3
3737
with:
3838
languages: ${{ env.LANGUAGE }}
3939

4040
- name: Build
4141
run: mvn --batch-mode --update-snapshots verify
4242

4343
- name: Perform CodeQL Analysis
44-
uses: github/codeql-action/analyze@v2
44+
uses: github/codeql-action/analyze@v3
4545
with:
4646
category: "/language:${{env.LANGUAGE}}"
4747
...

.github/workflows/stale.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
stale:
77
runs-on: ubuntu-latest
88
steps:
9-
- uses: actions/stale@v4
9+
- uses: actions/stale@v9
1010
with:
1111
stale-issue-message: 'This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution!'
1212
close-issue-message: 'Please reopen this issue once you have made the required changes. If you need help, feel free to ask in our [Discord](https://the-algorithms.com/discord) server or ping one of the maintainers here. Thank you for your contribution!'

.github/workflows/update_directory.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ubuntu-latest
2626
steps:
2727
- uses: actions/checkout@master
28-
- uses: actions/setup-python@v4
28+
- uses: actions/setup-python@v5
2929
with:
3030
python-version: '3.x'
3131
- name: Update Directory

DIRECTORY.md

+16-7
Large diffs are not rendered by default.

src/main/java/com/thealgorithms/backtracking/MColoring.java

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.thealgorithms.backtracking;
22

3-
import java.io.*;
43
import java.util.*;
54

65
/**

src/main/java/com/thealgorithms/ciphers/ProductCipher.java

+54-53
Original file line numberDiff line numberDiff line change
@@ -5,67 +5,68 @@
55
class ProductCipher {
66

77
public static void main(String[] args) {
8-
Scanner sc = new Scanner(System.in);
9-
System.out.println("Enter the input to be encrypted: ");
10-
String substitutionInput = sc.nextLine();
11-
System.out.println(" ");
12-
System.out.println("Enter a number: ");
13-
int n = sc.nextInt();
8+
try (Scanner sc = new Scanner(System.in)) {
9+
System.out.println("Enter the input to be encrypted: ");
10+
String substitutionInput = sc.nextLine();
11+
System.out.println(" ");
12+
System.out.println("Enter a number: ");
13+
int n = sc.nextInt();
1414

15-
// Substitution encryption
16-
StringBuffer substitutionOutput = new StringBuffer();
17-
for (int i = 0; i < substitutionInput.length(); i++) {
18-
char c = substitutionInput.charAt(i);
19-
substitutionOutput.append((char) (c + 5));
20-
}
21-
System.out.println(" ");
22-
System.out.println("Substituted text: ");
23-
System.out.println(substitutionOutput);
15+
// Substitution encryption
16+
StringBuffer substitutionOutput = new StringBuffer();
17+
for (int i = 0; i < substitutionInput.length(); i++) {
18+
char c = substitutionInput.charAt(i);
19+
substitutionOutput.append((char) (c + 5));
20+
}
21+
System.out.println(" ");
22+
System.out.println("Substituted text: ");
23+
System.out.println(substitutionOutput);
2424

25-
// Transposition encryption
26-
String transpositionInput = substitutionOutput.toString();
27-
int modulus;
28-
if ((modulus = transpositionInput.length() % n) != 0) {
29-
modulus = n - modulus;
25+
// Transposition encryption
26+
String transpositionInput = substitutionOutput.toString();
27+
int modulus;
28+
if ((modulus = transpositionInput.length() % n) != 0) {
29+
modulus = n - modulus;
3030

31-
for (; modulus != 0; modulus--) {
32-
transpositionInput += "/";
31+
for (; modulus != 0; modulus--) {
32+
transpositionInput += "/";
33+
}
3334
}
34-
}
35-
StringBuffer transpositionOutput = new StringBuffer();
36-
System.out.println(" ");
37-
System.out.println("Transposition Matrix: ");
38-
for (int i = 0; i < n; i++) {
39-
for (int j = 0; j < transpositionInput.length() / n; j++) {
40-
char c = transpositionInput.charAt(i + (j * n));
41-
System.out.print(c);
42-
transpositionOutput.append(c);
35+
StringBuffer transpositionOutput = new StringBuffer();
36+
System.out.println(" ");
37+
System.out.println("Transposition Matrix: ");
38+
for (int i = 0; i < n; i++) {
39+
for (int j = 0; j < transpositionInput.length() / n; j++) {
40+
char c = transpositionInput.charAt(i + (j * n));
41+
System.out.print(c);
42+
transpositionOutput.append(c);
43+
}
44+
System.out.println();
4345
}
44-
System.out.println();
45-
}
46-
System.out.println(" ");
47-
System.out.println("Final encrypted text: ");
48-
System.out.println(transpositionOutput);
46+
System.out.println(" ");
47+
System.out.println("Final encrypted text: ");
48+
System.out.println(transpositionOutput);
4949

50-
// Transposition decryption
51-
n = transpositionOutput.length() / n;
52-
StringBuffer transpositionPlaintext = new StringBuffer();
53-
for (int i = 0; i < n; i++) {
54-
for (int j = 0; j < transpositionOutput.length() / n; j++) {
55-
char c = transpositionOutput.charAt(i + (j * n));
56-
transpositionPlaintext.append(c);
50+
// Transposition decryption
51+
n = transpositionOutput.length() / n;
52+
StringBuffer transpositionPlaintext = new StringBuffer();
53+
for (int i = 0; i < n; i++) {
54+
for (int j = 0; j < transpositionOutput.length() / n; j++) {
55+
char c = transpositionOutput.charAt(i + (j * n));
56+
transpositionPlaintext.append(c);
57+
}
5758
}
58-
}
5959

60-
// Substitution decryption
61-
StringBuffer plaintext = new StringBuffer();
62-
for (int i = 0; i < transpositionPlaintext.length(); i++) {
63-
char c = transpositionPlaintext.charAt(i);
64-
plaintext.append((char) (c - 5));
65-
}
60+
// Substitution decryption
61+
StringBuffer plaintext = new StringBuffer();
62+
for (int i = 0; i < transpositionPlaintext.length(); i++) {
63+
char c = transpositionPlaintext.charAt(i);
64+
plaintext.append((char) (c - 5));
65+
}
6666

67-
System.out.println("Plaintext: ");
68-
System.out.println(plaintext);
69-
sc.close();
67+
System.out.println("Plaintext: ");
68+
System.out.println(plaintext);
69+
sc.close();
70+
}
7071
}
7172
}

src/main/java/com/thealgorithms/datastructures/dynamicarray/DynamicArray.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public String toString() {
145145
* @return Iterator a Dynamic Array Iterator
146146
*/
147147
@Override
148-
public Iterator iterator() {
148+
public Iterator<E> iterator() {
149149
return new DynamicArrayIterator();
150150
}
151151

src/main/java/com/thealgorithms/datastructures/graphs/BellmanFord.java

+57-52
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import java.util.*;
44

5-
class BellmanFord /*Implementation of Bellman ford to detect negative cycles. Graph accepts inputs
6-
in form of edges which have start vertex, end vertex and weights. Vertices should be labelled with a
7-
number between 0 and total number of vertices-1,both inclusive*/
5+
class BellmanFord /*
6+
* Implementation of Bellman ford to detect negative cycles. Graph accepts
7+
* inputs
8+
* in form of edges which have start vertex, end vertex and weights. Vertices
9+
* should be labelled with a
10+
* number between 0 and total number of vertices-1,both inclusive
11+
*/
812
{
913

1014
int vertex, edge;
@@ -36,7 +40,7 @@ public Edge(int a, int b, int c) {
3640

3741
/**
3842
* @param p[] Parent array which shows updates in edges
39-
* @param i Current vertex under consideration
43+
* @param i Current vertex under consideration
4044
*/
4145
void printPath(int[] p, int i) {
4246
if (p[i] == -1) { // Found the path back to parent
@@ -52,64 +56,65 @@ public static void main(String[] args) {
5256
}
5357

5458
public void go() { // shows distance to all vertices // Interactive run for understanding the
55-
// class first time. Assumes source vertex is 0 and
56-
Scanner sc = new Scanner(System.in); // Grab scanner object for user input
57-
int i, v, e, u, ve, w, j, neg = 0;
58-
System.out.println("Enter no. of vertices and edges please");
59-
v = sc.nextInt();
60-
e = sc.nextInt();
61-
Edge[] arr = new Edge[e]; // Array of edges
62-
System.out.println("Input edges");
63-
for (i = 0; i < e; i++) {
64-
u = sc.nextInt();
65-
ve = sc.nextInt();
66-
w = sc.nextInt();
67-
arr[i] = new Edge(u, ve, w);
68-
}
69-
int[] dist = new int[v]; // Distance array for holding the finalized shortest path distance
70-
// between source
71-
// and all vertices
72-
int[] p = new int[v]; // Parent array for holding the paths
73-
for (i = 0; i < v; i++) {
74-
dist[i] = Integer.MAX_VALUE; // Initializing distance values
75-
}
76-
dist[0] = 0;
77-
p[0] = -1;
78-
for (i = 0; i < v - 1; i++) {
59+
try ( // class first time. Assumes source vertex is 0 and
60+
Scanner sc = new Scanner(System.in)) {
61+
int i, v, e, u, ve, w, j, neg = 0;
62+
System.out.println("Enter no. of vertices and edges please");
63+
v = sc.nextInt();
64+
e = sc.nextInt();
65+
Edge[] arr = new Edge[e]; // Array of edges
66+
System.out.println("Input edges");
67+
for (i = 0; i < e; i++) {
68+
u = sc.nextInt();
69+
ve = sc.nextInt();
70+
w = sc.nextInt();
71+
arr[i] = new Edge(u, ve, w);
72+
}
73+
int[] dist = new int[v]; // Distance array for holding the finalized shortest path distance
74+
// between source
75+
// and all vertices
76+
int[] p = new int[v]; // Parent array for holding the paths
77+
for (i = 0; i < v; i++) {
78+
dist[i] = Integer.MAX_VALUE; // Initializing distance values
79+
}
80+
dist[0] = 0;
81+
p[0] = -1;
82+
for (i = 0; i < v - 1; i++) {
83+
for (j = 0; j < e; j++) {
84+
if (dist[arr[j].u] != Integer.MAX_VALUE && dist[arr[j].v] > dist[arr[j].u] + arr[j].w) {
85+
dist[arr[j].v] = dist[arr[j].u] + arr[j].w; // Update
86+
p[arr[j].v] = arr[j].u;
87+
}
88+
}
89+
}
90+
// Final cycle for negative checking
7991
for (j = 0; j < e; j++) {
8092
if (dist[arr[j].u] != Integer.MAX_VALUE && dist[arr[j].v] > dist[arr[j].u] + arr[j].w) {
81-
dist[arr[j].v] = dist[arr[j].u] + arr[j].w; // Update
82-
p[arr[j].v] = arr[j].u;
93+
neg = 1;
94+
System.out.println("Negative cycle");
95+
break;
8396
}
8497
}
85-
}
86-
// Final cycle for negative checking
87-
for (j = 0; j < e; j++) {
88-
if (dist[arr[j].u] != Integer.MAX_VALUE && dist[arr[j].v] > dist[arr[j].u] + arr[j].w) {
89-
neg = 1;
90-
System.out.println("Negative cycle");
91-
break;
92-
}
93-
}
94-
if (neg == 0) { // Go ahead and show results of computation
95-
System.out.println("Distances are: ");
96-
for (i = 0; i < v; i++) {
97-
System.out.println(i + " " + dist[i]);
98-
}
99-
System.out.println("Path followed:");
100-
for (i = 0; i < v; i++) {
101-
System.out.print("0 ");
102-
printPath(p, i);
103-
System.out.println();
98+
if (neg == 0) { // Go ahead and show results of computation
99+
System.out.println("Distances are: ");
100+
for (i = 0; i < v; i++) {
101+
System.out.println(i + " " + dist[i]);
102+
}
103+
System.out.println("Path followed:");
104+
for (i = 0; i < v; i++) {
105+
System.out.print("0 ");
106+
printPath(p, i);
107+
System.out.println();
108+
}
104109
}
110+
sc.close();
105111
}
106-
sc.close();
107112
}
108113

109114
/**
110115
* @param source Starting vertex
111-
* @param end Ending vertex
112-
* @param Edge Array of edges
116+
* @param end Ending vertex
117+
* @param Edge Array of edges
113118
*/
114119
public void show(int source, int end,
115120
Edge[] arr) { // be created by using addEdge() method and passed by calling getEdgeArray()

src/main/java/com/thealgorithms/datastructures/lists/CircleLinkedList.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void append(E value) {
5353

5454
// utility function for traversing the list
5555
public String toString() {
56-
Node p = head.next;
56+
Node<E> p = head.next;
5757
String s = "[ ";
5858
while (p != head) {
5959
s += p.value;
@@ -91,7 +91,7 @@ public E remove(int pos) {
9191
}
9292

9393
public static void main(String[] args) {
94-
CircleLinkedList cl = new CircleLinkedList<String>();
94+
CircleLinkedList<Integer> cl = new CircleLinkedList<>();
9595
cl.append(12);
9696
System.out.println(cl);
9797
cl.append(23);

src/main/java/com/thealgorithms/datastructures/lists/CursorLinkedList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void remove(T element) {
134134
}
135135

136136
private void free(int index) {
137-
Node os_node = cursorSpace[os];
137+
Node<T> os_node = cursorSpace[os];
138138
int os_next = os_node.next;
139139
cursorSpace[os].next = index;
140140
cursorSpace[index].element = null;

0 commit comments

Comments
 (0)