Skip to content

Commit

Permalink
Fix editorconfig issues (iiitv#331)
Browse files Browse the repository at this point in the history
* use eclint

* fix source files

* define eclint version

This will help us avoid issues in the future

* fix indentation issues in CountingSort.java
  • Loading branch information
aviaryan authored Jun 20, 2017
1 parent fc1413b commit 2daf0a6
Show file tree
Hide file tree
Showing 39 changed files with 631 additions and 627 deletions.
10 changes: 7 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true

[*.{go,c,cpp}]
charset = utf-8
indent_style = tab
tab_width = 4
trim_trailing_whitespace = true
Expand All @@ -15,12 +15,16 @@ indent_style = tab
tab_width = 2
trim_trailing_whitespace = true

[.{py,java}]
charset = utf-8
[*.{py,java}]
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.{c,cpp,java,js}]
block_comment_start = /*
block_comment = *
block_comment_end = */

[*.yml]
indent_style = space
indent_size = 2
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ install:
script:
- ./.bin/test_running.sh
- coala --ci
- if editorconfig-tools check **/* | grep " failed "; then false; else true; fi
- eclint check "**/*.{java,c,cpp,js}"
126 changes: 63 additions & 63 deletions bin_sort/BinSort.java
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
import java.util.Random;

class Node {
public double data;
public Node next;
public double data;
public Node next;

public Node(double data) {
this.data = data;
next = null;
}
public Node(double data) {
this.data = data;
next = null;
}
}

// Time Complexity O(n)-> avg case and O(n^2)-> Worst Case
// constraints:- 0<=A[i]<1
public class BinSort {
public static void binSort(Node[] b, double[] a) {
for (int i = 0; i < a.length; i++) {
int ins = (int) (a[i] * b.length);
if (b[ins] == null) {
b[ins] = new Node(a[i]);
} else {
boolean check = true;
Node temp = b[ins];
while (temp.next != null) {
if (a[i] > temp.next.data) {
temp = temp.next;
} else {
if (a[i] < temp.data)
break;
Node newNode = new Node(a[i]);
newNode.next = temp.next;
temp.next = newNode;
check = false;
break;
}
}
if (check) {
if (a[i] >= temp.data) {
Node newNode = new Node(a[i]);
temp.next = newNode;
} else {
double loc = temp.data;
temp.data = a[i];
Node newNode = new Node(loc);
newNode.next = temp.next;
temp.next = newNode;
}
}
}
}
int j = 0;
for (int i = 0; i < b.length; i++) {
while (b[i] != null) {
a[j++] = b[i].data;
b[i] = b[i].next;
}
}
}
public static void binSort(Node[] b, double[] a) {
for (int i = 0; i < a.length; i++) {
int ins = (int) (a[i] * b.length);
if (b[ins] == null) {
b[ins] = new Node(a[i]);
} else {
boolean check = true;
Node temp = b[ins];
while (temp.next != null) {
if (a[i] > temp.next.data) {
temp = temp.next;
} else {
if (a[i] < temp.data)
break;
Node newNode = new Node(a[i]);
newNode.next = temp.next;
temp.next = newNode;
check = false;
break;
}
}
if (check) {
if (a[i] >= temp.data) {
Node newNode = new Node(a[i]);
temp.next = newNode;
} else {
double loc = temp.data;
temp.data = a[i];
Node newNode = new Node(loc);
newNode.next = temp.next;
temp.next = newNode;
}
}
}
}
int j = 0;
for (int i = 0; i < b.length; i++) {
while (b[i] != null) {
a[j++] = b[i].data;
b[i] = b[i].next;
}
}
}

public static void main(String[] args) {
Node[] b = new Node[10];
Random ran = new Random();
int n = 100;
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = ran.nextDouble();
}
binSort(b, a);
for (int i = 0; i < n; i++) {
System.out.print(a[i] + " ");
}
System.out.println(" ");
}
public static void main(String[] args) {
Node[] b = new Node[10];
Random ran = new Random();
int n = 100;
double[] a = new double[n];
for (int i = 0; i < n; i++) {
a[i] = ran.nextDouble();
}
binSort(b, a);
for (int i = 0; i < n; i++) {
System.out.print(a[i] + " ");
}
System.out.println(" ");
}
}

8 changes: 4 additions & 4 deletions binary_search/BinarySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ static int binarySearch(int[] arr, int searchElement) {
int right = arr.length - 1;
while (left <= right) {
int mid = (left + right) / 2;
if (arr[mid] == searchElement) { // Element found
if (arr[mid] == searchElement) { // Element found
return mid;
}
if (arr[mid] < searchElement) { // Look in right half
if (arr[mid] < searchElement) { // Look in right half
left = mid + 1;
} else { // Look in left half
} else { // Look in left half
right = mid - 1;
}
}
Expand All @@ -23,7 +23,7 @@ public static void main(String[] args) {
int[] searchArr = new int[] {1, 35, 112, 324, 67};
int pos;
for (int i = 0; i < searchArr.length; i++) {
pos = binarySearch(arr, searchArr[i]); //search key and get poistion
pos = binarySearch(arr, searchArr[i]); //search key and get poistion
if (pos >= 0) {
System.out.println(searchArr[i] + "-> found at index : " + pos);
} else {
Expand Down
4 changes: 2 additions & 2 deletions binary_search/binary_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function binarySearchIterative (arr, item) {
:param arr: List of elements to search from
:param item: Element to search for
:return: returns index if element found else -1
*/
*/
let begin = 0;
let end = arr.length - 1;
while (begin <= end) {
Expand All @@ -28,7 +28,7 @@ function binarySearchRecursive (arr, item, begin, end) {
:param begin: Left limit of array
:param end: Right limit of array
:return: returns index if element found else -1
*/
*/
if (begin <= end) {
let mid = Math.floor((begin + end) / 2);
if (arr[mid] === item) {
Expand Down
Loading

0 comments on commit 2daf0a6

Please sign in to comment.