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