Skip to content

Code cleanup #4246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.thealgorithms.conversions;
import java.util.Scanner;

/**
* Converts any Octal Number to a Binary Number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.thealgorithms.datastructures.graphs;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Stack;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,12 @@ public class DoublyLinkedList {
*/
private LinkOperations linkOperations;

/**
* Size refers to the number of elements present in the list
*/
private int size;

/**
* Default Constructor
*/
public DoublyLinkedList() {
head = null;
tail = null;
size = 0;
}

/**
Expand All @@ -55,7 +49,6 @@ public DoublyLinkedList(int[] array) {
for (int i : array) {
linkOperations.insertTail(i, this);
}
size = array.length;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,5 @@ private class Node {

private int data;
private Node next;

public Node(int d) {
this.data = d;
next = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,7 @@ public Node reverseList(Node node) {
public void clear() {
Node cur = head;
while (cur != null) {
Node prev = cur;
cur = cur.next;
prev = null; // clear to let GC do its work
}
head = null;
size = 0;
Expand Down Expand Up @@ -346,9 +344,7 @@ public void delete() {
public void deleteNth(int position) {
checkBounds(position, 0, size - 1);
if (position == 0) {
Node destroy = head;
head = head.next;
destroy = null;
/* clear to let GC do its work */
size--;
return;
Expand All @@ -358,10 +354,7 @@ public void deleteNth(int position) {
cur = cur.next;
}

Node destroy = cur.next;
cur.next = cur.next.next;
destroy = null; // clear to let GC do its work

size--;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static void main(String[] args) {
private Item data;

private static NodeStack<?> head;
private NodeStack<?> next;
private NodeStack<?> previous;
private static int size = 0;

Expand Down Expand Up @@ -72,7 +71,7 @@ public void push(Item item) {
} else {
newNs.setPrevious(NodeStack.head);
NodeStack.head.setNext(newNs);
NodeStack.head.setHead(newNs);
NodeStack.setHead(newNs);
}

NodeStack.setSize(NodeStack.getSize() + 1);
Expand All @@ -86,7 +85,7 @@ public void push(Item item) {
public Item pop() {
Item item = (Item) NodeStack.head.getData();

NodeStack.head.setHead(NodeStack.head.getPrevious());
NodeStack.setHead(NodeStack.head.getPrevious());
NodeStack.head.setNext(null);

NodeStack.setSize(NodeStack.getSize() - 1);
Expand Down Expand Up @@ -133,23 +132,11 @@ public void print() {
}
}

/**
* Getters and setters (private)
*/
private NodeStack<?> getHead() {
return NodeStack.head;
}

private static void setHead(NodeStack<?> ns) {
NodeStack.head = ns;
}

private NodeStack<?> getNext() {
return next;
}

private void setNext(NodeStack<?> next) {
this.next = next;
}

private NodeStack<?> getPrevious() {
Expand All @@ -171,8 +158,4 @@ private static void setSize(int size) {
private Item getData() {
return this.data;
}

private void setData(Item item) {
this.data = item;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ private class Node {
}

private Node root;
private int size;

public GenericTree() { // Constructor
Scanner scn = new Scanner(System.in);
root = create_treeG(null, 0, scn);
Expand All @@ -44,7 +42,6 @@ private Node create_treeG(Node node, int childindx, Scanner scn) {
int number = scn.nextInt();
for (int i = 0; i < number; i++) {
Node child = create_treeG(node, i, scn);
size++;
node.child.add(child);
}
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ private class Node {

int item;
Node left, right;

public Node(int key) {
item = key;
left = right = null;
}
}

// Using an arraylist to store the inorder traversal of the given binary tree
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static void main(String[] args) {
int inputX0 = sc.nextInt();
int toPrint = nearestRightKey(root, inputX0);
System.out.println("Key: " + toPrint);
sc.close();
}

public static NRKTree BuildTree() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.thealgorithms.dynamicprogramming;

import java.util.Scanner;

/**
* Given a string containing just the characters '(' and ')', find the length of
* the longest valid (well-formed) parentheses substring.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ public static void main(String[] args) {
}
}
System.out.println(determinant(a, n));
in.close();
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/thealgorithms/maths/DudeneyNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
*/
package com.thealgorithms.maths;

import java.io.*;

public class DudeneyNumber {

// returns True if the number is a Dudeney number and False if it is not a Dudeney number.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/thealgorithms/maths/KeithNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ public static void main(String[] args) {
} else {
System.out.println("No, the given number is not a Keith number.");
}
in.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void main(String[] args) {
System.out.println("Please enter second number >> ");
int num2 = input.nextInt();
System.out.println("The least common multiple of two numbers is >> " + lcm(num1, num2));
input.close();
}

/*
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/thealgorithms/maths/MagicSquare.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ public static void main(String[] args) {
}
System.out.println();
}
sc.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public static void main(String[] args) {
}

System.out.println("The two non repeating elements are " + num1 + " and " + num2);
sc.close();
}
/*
Explanation of the code:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.thealgorithms.maths;

import java.util.Scanner;

/*
*To learn about the method, visit the link below :
* https://en.wikipedia.org/wiki/Newton%27s_method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ private static class Schedule { // Schedule class

int t = 0; // Time required for the operation to be performed
int d = 0; // Time the job should be completed
int s = 0; // Start time of the task
int f = 0; // End time of the operation

public Schedule(int t, int d) {
this.t = t;
this.d = d;
Expand Down Expand Up @@ -46,8 +43,6 @@ public static void main(String[] args) throws IOException {
int tryTime = 0; // Total time worked
int lateness = 0; // Lateness
for (int j = 0; j < indexCount - 1; j++) {
array[j].s = tryTime; // Start time of the task
array[j].f = tryTime + array[j].t; // Time finished
tryTime = tryTime + array[j].t; // Add total work time
// Lateness
lateness = lateness + Math.max(0, tryTime - array[j].d);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/thealgorithms/misc/Sort012D.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void main(String[] args) {
a[i] = np.nextInt();
}
sort012(a);
np.close();
}

public static void sort012(int[] a) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/thealgorithms/misc/Sparcity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ public static void main(String[] args) {
}
}
System.out.println("Sparcity of matrix is: " + sparcity(mat));
in.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void main(String[] args) {
System.out.println("Brute Force Approach\n" + (th.BruteForce(arr, ts)) + "\n");
System.out.println("Two Pointer Approach\n" + (th.TwoPointer(arr, ts)) + "\n");
System.out.println("Hashmap Approach\n" + (th.Hashmap(arr, ts)));
scan.close();
}

public List<List<Integer>> BruteForce(int[] nums, int target) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/thealgorithms/others/BoyerMoore.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,6 @@ public static void main(String[] args) {
a[i] = input.nextInt();
}
System.out.println("the majority element is " + findmajor(a));
input.close();
}
}
2 changes: 0 additions & 2 deletions src/main/java/com/thealgorithms/others/CountWords.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.thealgorithms.others;

import java.util.Scanner;

/**
* @author Marcus
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static void main(String[] args) {
}
String res = n == 1 ? "1 Happy number" : "Sad number";
System.out.println(res);
in.close();
}

private static int sumSquares(int n) {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/thealgorithms/others/Huffman.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,6 @@ public static void main(String[] args) {

// print the codes by traversing the tree
printCode(root, "");
s.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public static void main(String[] args) {
}
}

Rotate g = new Rotate();
g.rotate(arr);
Rotate.rotate(arr);
printMatrix(arr);
}
sc.close();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.thealgorithms.others.cn;

import java.util.ArrayList;
import java.util.List;

final public class HammingDistance {
private HammingDistance() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static void main(String[] args) {
}
boolean found = t.getResult() || t1.getResult() || t2.getResult() || t3.getResult();
System.out.println("Found = " + found);
in.close();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ static int binarySearch(int[] arr, int target) {
}

public static void main(String[] args) {
PerfectBinarySearch BinarySearch = new PerfectBinarySearch();
int[] array = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
assert BinarySearch.binarySearch(array, -1) == -1;
assert BinarySearch.binarySearch(array, 11) == -1;
assert PerfectBinarySearch.binarySearch(array, -1) == -1;
assert PerfectBinarySearch.binarySearch(array, 11) == -1;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.thealgorithms.searches;

import java.util.Arrays;

public class SearchInARowAndColWiseSortedMatrix {
/**
* Search a key in row and column wise sorted matrix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void main(String[] args) {
int num = sc.nextInt();
long ans = squareRoot(num);
System.out.println("The square root is : " + ans);
sc.close();
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package com.thealgorithms.searches;
import java.util.*;
public class sortOrderAgnosticBinarySearch {
public static int find(int[] arr, int key) {
int start = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ public static void main(String[] args) {
for (int i = 0; i < a.length; i++) {
System.out.print(a[i] + " ");
}
inp.close();
}
}
Loading