mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-10 04:26:27 +08:00
@ -35,6 +35,7 @@ class DecimalToBinary {
|
||||
n /= 2;
|
||||
} //converting decimal to binary
|
||||
System.out.println("\tBinary number: " + b);
|
||||
input.close();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,13 @@ import java.util.*;
|
||||
|
||||
public class RomanToInteger {
|
||||
|
||||
private static Map<Character, Integer> map = new HashMap<Character, Integer>() {{
|
||||
private static Map<Character, Integer> map = new HashMap<Character, Integer>() {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 87605733047260530L;
|
||||
|
||||
{
|
||||
put('I', 1);
|
||||
put('V', 5);
|
||||
put('X', 10);
|
||||
|
@ -26,12 +26,15 @@ public class CircularBuffer {
|
||||
return i % _buffer_size;
|
||||
}
|
||||
|
||||
|
||||
public Character readOutChar() {
|
||||
Character result = null;
|
||||
|
||||
|
||||
//if we have data to read
|
||||
if (_readable_data.get() > 0) {
|
||||
result = new Character(_buffer[getTrueIndex(_read_index)]);
|
||||
|
||||
result = Character.valueOf(_buffer[getTrueIndex(_read_index)]);
|
||||
_readable_data.decrementAndGet();
|
||||
_read_index++;
|
||||
}
|
||||
|
@ -108,7 +108,7 @@ class Graph<E extends Comparable<E>> {
|
||||
public class ConnectedComponent {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Graph graphChars = new Graph();
|
||||
Graph<Character> graphChars = new Graph<>();
|
||||
|
||||
// Graph 1
|
||||
graphChars.addEdge('a', 'b');
|
||||
@ -123,7 +123,7 @@ public class ConnectedComponent {
|
||||
|
||||
graphChars.addEdge('w', 'w');
|
||||
|
||||
Graph graphInts = new Graph();
|
||||
Graph<Integer> graphInts = new Graph<>();
|
||||
|
||||
// Graph 2
|
||||
graphInts.addEdge(1, 2);
|
||||
|
@ -10,7 +10,7 @@ class Cycle {
|
||||
private int[][] adjacencyMatrix;
|
||||
private boolean[] visited;
|
||||
ArrayList<ArrayList<Integer>> cycles = new ArrayList<ArrayList<Integer>>();
|
||||
private boolean[] finalCycles;
|
||||
|
||||
|
||||
public Cycle() {
|
||||
Scanner in = new Scanner(System.in);
|
||||
@ -34,6 +34,7 @@ class Cycle {
|
||||
end = in.nextInt();
|
||||
adjacencyMatrix[start][end] = 1;
|
||||
}
|
||||
in.close();
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package DataStructures.Graphs;
|
||||
|
||||
import java.lang.*;
|
||||
|
||||
/**
|
||||
* A Java program for Prim's Minimum Spanning Tree (MST) algorithm.
|
||||
* adjacency matrix representation of the graph
|
||||
|
@ -12,7 +12,6 @@ class LinkedList {
|
||||
|
||||
public void insert(int data) {
|
||||
|
||||
Node temp = Head;
|
||||
Node newnode = new Node(data);
|
||||
|
||||
size++;
|
||||
|
@ -8,6 +8,7 @@ public class Main {
|
||||
int choice, key;
|
||||
|
||||
HashMap h = new HashMap(7);
|
||||
Scanner In = new Scanner(System.in);
|
||||
|
||||
while (true) {
|
||||
System.out.println("Enter your Choice :");
|
||||
@ -15,9 +16,7 @@ public class Main {
|
||||
System.out.println("2. Delete Key");
|
||||
System.out.println("3. Print Table");
|
||||
System.out.println("4. Exit");
|
||||
|
||||
Scanner In = new Scanner(System.in);
|
||||
|
||||
|
||||
choice = In.nextInt();
|
||||
|
||||
switch (choice) {
|
||||
@ -39,10 +38,11 @@ public class Main {
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
In.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
In.close();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@ import java.util.Objects;
|
||||
|
||||
public class CursorLinkedList<T> {
|
||||
|
||||
|
||||
private static class Node<T> {
|
||||
|
||||
T element;
|
||||
@ -13,13 +14,8 @@ public class CursorLinkedList<T> {
|
||||
this.element = element;
|
||||
this.next = next;
|
||||
}
|
||||
|
||||
boolean isEmpty() {
|
||||
return element == null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private final int os;
|
||||
private int head;
|
||||
private final Node<T>[] cursorSpace;
|
||||
@ -27,6 +23,7 @@ public class CursorLinkedList<T> {
|
||||
private final static int CURSOR_SPACE_SIZE = 100;
|
||||
|
||||
|
||||
|
||||
{
|
||||
// init at loading time
|
||||
cursorSpace = new Node[CURSOR_SPACE_SIZE];
|
||||
|
@ -120,9 +120,9 @@ public class SinglyLinkedList {
|
||||
cur = cur.next;
|
||||
}
|
||||
|
||||
Node destroy = cur.next;
|
||||
//Node destroy = cur.next;
|
||||
cur.next = cur.next.next;
|
||||
destroy = null; // clear to let GC do its work
|
||||
//destroy = null; // clear to let GC do its work
|
||||
|
||||
size--;
|
||||
}
|
||||
|
@ -330,5 +330,6 @@ public class RedBlackBST {
|
||||
printTree(root);
|
||||
System.out.println("Pre order");
|
||||
printTreepre(root);
|
||||
scan.close();
|
||||
}
|
||||
}
|
@ -26,6 +26,7 @@ public class MinimizingLateness {
|
||||
BufferedReader in = new BufferedReader(new FileReader("MinimizingLateness/lateness_data.txt"));
|
||||
String ch = in.readLine();
|
||||
if (ch == null || ch.isEmpty()) {
|
||||
in.close();
|
||||
return;
|
||||
}
|
||||
int indexCount = Integer.parseInt(ch);
|
||||
|
@ -57,8 +57,7 @@ public class heap_sort {
|
||||
// Driver program
|
||||
public static void main(String args[]) {
|
||||
int arr[] = {12, 11, 13, 5, 6, 7};
|
||||
int n = arr.length;
|
||||
|
||||
|
||||
heap_sort ob = new heap_sort();
|
||||
ob.sort(arr);
|
||||
|
||||
|
@ -20,7 +20,7 @@ class MergeSort implements SortAlgorithm {
|
||||
* @return sorted array
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
public <T extends Comparable<T>> T[] sort(T[] unsorted) {
|
||||
doSort(unsorted, 0, unsorted.length - 1);
|
||||
return unsorted;
|
||||
|
Reference in New Issue
Block a user