Skip to content

Commit c41746c

Browse files
authored
Merge branch 'master' into all-contributors/add-tttson
2 parents c16d644 + cc61e9e commit c41746c

File tree

5 files changed

+155
-1
lines changed

5 files changed

+155
-1
lines changed

.all-contributorsrc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,41 @@
1313
"contributions": [
1414
"code"
1515
]
16+
},
17+
"login": "ADVAITH18",
18+
"name": "ADVAITH U",
19+
"avatar_url": "https://avatars0.githubusercontent.com/u/45172876?v=4",
20+
"profile": "https://github.com/ADVAITH18",
21+
"contributions": [
22+
"code"
23+
]
24+
},
25+
{
26+
"login": "ankurpalmia",
27+
"name": "Ankur Palmia",
28+
"avatar_url": "https://avatars0.githubusercontent.com/u/34860089?v=4",
29+
"profile": "https://github.com/ankurpalmia",
30+
"contributions": [
31+
"code"
32+
]
33+
},
34+
{
35+
"login": "JD235",
36+
"name": "JD",
37+
"avatar_url": "https://avatars0.githubusercontent.com/u/43887713?v=4",
38+
"profile": "https://github.com/JD235",
39+
"contributions": [
40+
"code"
41+
]
42+
},
43+
{
44+
"login": "syk007",
45+
"name": "syk007",
46+
"avatar_url": "https://avatars2.githubusercontent.com/u/31596670?v=4",
47+
"profile": "https://github.com/syk007",
48+
"contributions": [
49+
"code"
50+
]
1651
}
1752
],
1853
"contributorsPerLine": 7,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import java.io.*;
2+
class DuplicateElimination
3+
{
4+
public static void main(String[] args) throws Exception
5+
{
6+
System.out.println("Removing Duplicate lines in file");
7+
BufferedReader br1 = new BufferedReader(new FileReader("input.txt"));
8+
PrintWriter pw = new PrintWriter("output.txt");
9+
String line = br1.readLine();
10+
while (line != null)
11+
{
12+
boolean available = false;
13+
BufferedReader br2 = new BufferedReader( new FileReader("output.txt") );
14+
String target = br2.readLine();
15+
while (target != null)
16+
{
17+
if (line.equals(target) )
18+
{
19+
available = true;
20+
break;
21+
}
22+
target = br2.readLine();
23+
}
24+
if (available == false)
25+
{
26+
pw.println(line);
27+
pw.flush();
28+
}
29+
line = br1.readLine();
30+
}
31+
}
32+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Hello World..!!
2+
Hello World..!!
3+
Hello World..!!
4+
What's up :)
5+
What's up :)
6+
What's up :)

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Java Algorithms
2-
[![All Contributors](https://img.shields.io/badge/all_contributors-1-orange.svg?style=flat-square)](#contributors)
2+
[![All Contributors](https://img.shields.io/badge/all_contributors-5-orange.svg?style=flat-square)](#contributors)
33

44
## Contributors ✨
55

@@ -10,6 +10,10 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
1010
<table>
1111
<tr>
1212
<td align="center"><a href="https://github.com/tttson"><img src="https://avatars2.githubusercontent.com/u/24596895?v=4" width="100px;" alt="T"/><br /><sub><b>T</b></sub></a><br /><a href="https://github.com/darpanjbora/Java-Algorithms/commits?author=tttson" title="Code">💻</a></td>
13+
<td align="center"><a href="https://github.com/ADVAITH18"><img src="https://avatars0.githubusercontent.com/u/45172876?v=4" width="100px;" alt="ADVAITH U"/><br /><sub><b>ADVAITH U</b></sub></a><br /><a href="https://github.com/darpanjbora/Java-Algorithms/commits?author=ADVAITH18" title="Code">💻</a></td>
14+
<td align="center"><a href="https://github.com/ankurpalmia"><img src="https://avatars0.githubusercontent.com/u/34860089?v=4" width="100px;" alt="Ankur Palmia"/><br /><sub><b>Ankur Palmia</b></sub></a><br /><a href="https://github.com/darpanjbora/Java-Algorithms/commits?author=ankurpalmia" title="Code">💻</a></td>
15+
<td align="center"><a href="https://github.com/JD235"><img src="https://avatars0.githubusercontent.com/u/43887713?v=4" width="100px;" alt="JD"/><br /><sub><b>JD</b></sub></a><br /><a href="https://github.com/darpanjbora/Java-Algorithms/commits?author=JD235" title="Code">💻</a></td>
16+
<td align="center"><a href="https://github.com/syk007"><img src="https://avatars2.githubusercontent.com/u/31596670?v=4" width="100px;" alt="syk007"/><br /><sub><b>syk007</b></sub></a><br /><a href="https://github.com/darpanjbora/Java-Algorithms/commits?author=syk007" title="Code">💻</a></td>
1317
</tr>
1418
</table>
1519

Sorting Algorithms/QuickSort.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Java program for implementation of QuickSort
2+
class QuickSort
3+
{
4+
/* This function takes last element as pivot,
5+
places the pivot element at its correct
6+
position in sorted array, and places all
7+
smaller (smaller than pivot) to left of
8+
pivot and all greater elements to right
9+
of pivot */
10+
int partition(int arr[], int low, int high)
11+
{
12+
int pivot = arr[high];
13+
int i = (low-1); // index of smaller element
14+
for (int j=low; j<high; j++)
15+
{
16+
// If current element is smaller than the pivot
17+
if (arr[j] < pivot)
18+
{
19+
i++;
20+
21+
// swap arr[i] and arr[j]
22+
int temp = arr[i];
23+
arr[i] = arr[j];
24+
arr[j] = temp;
25+
}
26+
}
27+
28+
// swap arr[i+1] and arr[high] (or pivot)
29+
int temp = arr[i+1];
30+
arr[i+1] = arr[high];
31+
arr[high] = temp;
32+
33+
return i+1;
34+
}
35+
36+
37+
/* The main function that implements QuickSort()
38+
arr[] --> Array to be sorted,
39+
low --> Starting index,
40+
high --> Ending index */
41+
void sort(int arr[], int low, int high)
42+
{
43+
if (low < high)
44+
{
45+
/* pi is partitioning index, arr[pi] is
46+
now at right place */
47+
int pi = partition(arr, low, high);
48+
49+
// Recursively sort elements before
50+
// partition and after partition
51+
sort(arr, low, pi-1);
52+
sort(arr, pi+1, high);
53+
}
54+
}
55+
56+
/* A utility function to print array of size n */
57+
static void printArray(int arr[])
58+
{
59+
int n = arr.length;
60+
for (int i=0; i<n; ++i)
61+
System.out.print(arr[i]+" ");
62+
System.out.println();
63+
}
64+
65+
// Driver program
66+
public static void main(String args[])
67+
{
68+
int arr[] = {10, 7, 8, 9, 1, 5};
69+
int n = arr.length;
70+
71+
QuickSort ob = new QuickSort();
72+
ob.sort(arr, 0, n-1);
73+
74+
System.out.println("sorted array");
75+
printArray(arr);
76+
}
77+
}

0 commit comments

Comments
 (0)