| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 63e5ce4 commit a5f42e2
25 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,7 @@ public static void main(String args[]) { | |||
| 27 | 27 | public static void conventionalConversion() { | |
| 28 | 28 | int n, b = 0, c = 0, d; | |
| 29 | 29 | Scanner input = new Scanner(System.in); | |
| 30 | - System.out.printf("Conventional conversion.\n\tEnter the decimal number: "); | ||
| 30 | + System.out.printf("Conventional conversion.%n Enter the decimal number: "); | ||
| 31 | 31 | n = input.nextInt(); | |
| 32 | 32 | while (n != 0) { | |
| 33 | 33 | d = n % 2; | |
@@ -46,7 +46,7 @@ public static void conventionalConversion() { | |||
| 46 | 46 | public static void bitwiseConversion() { | |
| 47 | 47 | int n, b = 0, c = 0, d; | |
| 48 | 48 | Scanner input = new Scanner(System.in); | |
| 49 | - System.out.printf("Bitwise conversion.\n\tEnter the decimal number: "); | ||
| 49 | + System.out.printf("Bitwise conversion.%n Enter the decimal number: "); | ||
| 50 | 50 | n = input.nextInt(); | |
| 51 | 51 | while (n != 0) { | |
| 52 | 52 | d = (n & 1); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ public class OctalToHexadecimal { | |||
| 15 | 15 | * @param s The Octal Number | |
| 16 | 16 | * @return The Decimal number | |
| 17 | 17 | */ | |
| 18 | - public static int OctToDec(String s) { | ||
| 18 | + public static int octToDec(String s) { | ||
| 19 | 19 | int i = 0; | |
| 20 | 20 | for (int j = 0; j < s.length(); j++) { | |
| 21 | 21 | char num = s.charAt(j); | |
@@ -32,7 +32,7 @@ public static int OctToDec(String s) { | |||
| 32 | 32 | * @param d The Decimal Number | |
| 33 | 33 | * @return The Hexadecimal number | |
| 34 | 34 | */ | |
| 35 | - public static String DecimalToHex(int d) { | ||
| 35 | + public static String decimalToHex(int d) { | ||
| 36 | 36 | String digits = "0123456789ABCDEF"; | |
| 37 | 37 | if (d <= 0) | |
| 38 | 38 | return "0"; | |
@@ -54,10 +54,10 @@ public static void main(String args[]) { | |||
| 54 | 54 | String oct = input.next(); | |
| 55 | 55 | ||
| 56 | 56 | // Pass the octal number to function and get converted deciaml form | |
| 57 | - int decimal = OctToDec(oct); | ||
| 57 | + int decimal = octToDec(oct); | ||
| 58 | 58 | ||
| 59 | 59 | // Pass the decimla number to function and get converted Hex form of the number | |
| 60 | - String hex = DecimalToHex(decimal); | ||
| 60 | + String hex = decimalToHex(decimal); | ||
| 61 | 61 | System.out.println("The Hexadecimal equivalant is: " + hex); | |
| 62 | 62 | input.close(); | |
| 63 | 63 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,7 +41,7 @@ public void add(final E element) { | |||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | public void put(final int index, E element) { | |
| 44 | - Objects.checkIndex(index, this.size); | ||
| 44 | + // Objects.checkIndex(index, this.size); | ||
| 45 | 45 | ||
| 46 | 46 | this.elements[index] = element; | |
| 47 | 47 | } | |
@@ -79,7 +79,7 @@ private void fastRemove(final Object[] elements, final int index) { | |||
| 79 | 79 | } | |
| 80 | 80 | ||
| 81 | 81 | private E getElement(final int index) { | |
| 82 | - Objects.checkIndex(index, this.size); | ||
| 82 | + // Objects.checkIndex(index, this.size); | ||
| 83 | 83 | return (E) this.elements[index]; | |
| 84 | 84 | } | |
| 85 | 85 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ class Edge | |||
| 23 | 23 | * @param v End vertex | |
| 24 | 24 | * @param c Weight | |
| 25 | 25 | */ | |
| 26 | - Edge(int a,int b,int c) | ||
| 26 | + public Edge(int a,int b,int c) | ||
| 27 | 27 | { | |
| 28 | 28 | u=a; | |
| 29 | 29 | v=b; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -127,8 +127,7 @@ public boolean removeEdge(int from, int to) { | |||
| 127 | 127 | * @return returns a string describing this graph | |
| 128 | 128 | */ | |
| 129 | 129 | public String toString() { | |
| 130 | - String s = new String(); | ||
| 131 | - s = " "; | ||
| 130 | + String s = " "; | ||
| 132 | 131 | for (int i = 0; i < this.numberOfVertices(); i++) { | |
| 133 | 132 | s = s + String.valueOf(i) + " "; | |
| 134 | 133 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -117,7 +117,21 @@ public String toString() { | |||
| 117 | 117 | * @return true if the keys on both elements are identical and the additional info objects | |
| 118 | 118 | * are identical. | |
| 119 | 119 | */ | |
| 120 | - public boolean equals(HeapElement otherHeapElement) { | ||
| 121 | - return (this.key == otherHeapElement.key) && (this.additionalInfo.equals(otherHeapElement.additionalInfo)); | ||
| 120 | + @Override | ||
| 121 | + public boolean equals(Object o) { | ||
| 122 | + if (o != null) { | ||
| 123 | + if (!(o instanceof HeapElement)) return false; | ||
| 124 | + HeapElement otherHeapElement = (HeapElement) o; | ||
| 125 | + return (this.key == otherHeapElement.key) && (this.additionalInfo.equals(otherHeapElement.additionalInfo)); | ||
| 126 | + } | ||
| 127 | + return false; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + @Override | ||
| 131 | + public int hashCode() { | ||
| 132 | + int result = 0; | ||
| 133 | + result = 31*result + (int) key; | ||
| 134 | + result = 31*result + (additionalInfo != null ? additionalInfo.hashCode() : 0); | ||
| 135 | + return result; | ||
| 122 | 136 | } | |
| 123 | 137 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,9 +49,9 @@ private void swap(int index1, int index2) { | |||
| 49 | 49 | // Toggle an element up to its right place as long as its key is lower than its parent's | |
| 50 | 50 | private void toggleUp(int elementIndex) { | |
| 51 | 51 | double key = maxHeap.get(elementIndex - 1).getKey(); | |
| 52 | - while (getElementKey((int) Math.floor(elementIndex / 2)) < key) { | ||
| 53 | - swap(elementIndex, (int) Math.floor(elementIndex / 2)); | ||
| 54 | - elementIndex = (int) Math.floor(elementIndex / 2); | ||
| 52 | + while (getElementKey((int) Math.floor(elementIndex / 2.0)) < key) { | ||
| 53 | + swap(elementIndex, (int) Math.floor(elementIndex / 2.0)); | ||
| 54 | + elementIndex = (int) Math.floor(elementIndex / 2.0); | ||
| 55 | 55 | } | |
| 56 | 56 | } | |
| 57 | 57 | ||
@@ -101,7 +101,7 @@ public void deleteElement(int elementIndex) { | |||
| 101 | 101 | maxHeap.set(elementIndex - 1, getElement(maxHeap.size())); | |
| 102 | 102 | maxHeap.remove(maxHeap.size()); | |
| 103 | 103 | // Shall the new element be moved up... | |
| 104 | - if (getElementKey(elementIndex) > getElementKey((int) Math.floor(elementIndex / 2))) toggleUp(elementIndex); | ||
| 104 | + if (getElementKey(elementIndex) > getElementKey((int) Math.floor(elementIndex / 2.0))) toggleUp(elementIndex); | ||
| 105 | 105 | // ... or down ? | |
| 106 | 106 | else if (((2 * elementIndex <= maxHeap.size()) && (getElementKey(elementIndex) < getElementKey(elementIndex * 2))) || | |
| 107 | 107 | ((2 * elementIndex < maxHeap.size()) && (getElementKey(elementIndex) < getElementKey(elementIndex * 2)))) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,9 +44,9 @@ private void swap(int index1, int index2) { | |||
| 44 | 44 | // Toggle an element up to its right place as long as its key is lower than its parent's | |
| 45 | 45 | private void toggleUp(int elementIndex) { | |
| 46 | 46 | double key = minHeap.get(elementIndex - 1).getKey(); | |
| 47 | - while (getElementKey((int) Math.floor(elementIndex / 2)) > key) { | ||
| 48 | - swap(elementIndex, (int) Math.floor(elementIndex / 2)); | ||
| 49 | - elementIndex = (int) Math.floor(elementIndex / 2); | ||
| 47 | + while (getElementKey((int) Math.floor(elementIndex / 2.0)) > key) { | ||
| 48 | + swap(elementIndex, (int) Math.floor(elementIndex / 2.0)); | ||
| 49 | + elementIndex = (int) Math.floor(elementIndex / 2.0); | ||
| 50 | 50 | } | |
| 51 | 51 | } | |
| 52 | 52 | ||
@@ -96,7 +96,7 @@ public void deleteElement(int elementIndex) { | |||
| 96 | 96 | minHeap.set(elementIndex - 1, getElement(minHeap.size())); | |
| 97 | 97 | minHeap.remove(minHeap.size()); | |
| 98 | 98 | // Shall the new element be moved up... | |
| 99 | - if (getElementKey(elementIndex) < getElementKey((int) Math.floor(elementIndex / 2))) toggleUp(elementIndex); | ||
| 99 | + if (getElementKey(elementIndex) < getElementKey((int)Math.floor(elementIndex / 2.0))) toggleUp(elementIndex); | ||
| 100 | 100 | // ... or down ? | |
| 101 | 101 | else if (((2 * elementIndex <= minHeap.size()) && (getElementKey(elementIndex) > getElementKey(elementIndex * 2))) || | |
| 102 | 102 | ((2 * elementIndex < minHeap.size()) && (getElementKey(elementIndex) > getElementKey(elementIndex * 2)))) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,7 @@ private Node(E value, Node<E> next) { | |||
| 14 | 14 | //For better O.O design this should be private allows for better black box design | |
| 15 | 15 | private int size; | |
| 16 | 16 | //this will point to dummy node; | |
| 17 | - private Node<E> head; | ||
| 17 | + private Node<E> head = null; | ||
| 18 | 18 | ||
| 19 | 19 | //constructer for class.. here we will make a dummy node for circly linked list implementation with reduced error catching as our list will never be empty; | |
| 20 | 20 | public CircleLinkedList() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,9 +86,12 @@ public void insertTail(int x) { | |||
| 86 | 86 | public Link deleteHead() { | |
| 87 | 87 | Link temp = head; | |
| 88 | 88 | head = head.next; // oldHead <--> 2ndElement(head) | |
| 89 | - head.previous = null; // oldHead --> 2ndElement(head) nothing pointing at old head so will be removed | ||
| 90 | - if (head == null) | ||
| 89 | + | ||
| 90 | + if (head == null) { | ||
| 91 | 91 | tail = null; | |
| 92 | + } else { | ||
| 93 | + head.previous = null; // oldHead --> 2ndElement(head) nothing pointing at old head so will be removed | ||
| 94 | + } | ||
| 92 | 95 | return temp; | |
| 93 | 96 | } | |
| 94 | 97 | ||
@@ -100,10 +103,13 @@ public Link deleteHead() { | |||
| 100 | 103 | public Link deleteTail() { | |
| 101 | 104 | Link temp = tail; | |
| 102 | 105 | tail = tail.previous; // 2ndLast(tail) <--> oldTail --> null | |
| 103 | - tail.next = null; // 2ndLast(tail) --> null | ||
| 106 | + | ||
| 104 | 107 | if (tail == null) { | |
| 105 | 108 | head = null; | |
| 109 | + } else{ | ||
| 110 | + tail.next = null; // 2ndLast(tail) --> null | ||
| 106 | 111 | } | |
| 112 | + | ||
| 107 | 113 | return temp; | |
| 108 | 114 | } | |
| 109 | 115 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments