Skip to content

Commit 0674828

Browse files
created bubbleSorting in java
0 parents  commit 0674828

File tree

4 files changed

+350
-0
lines changed

4 files changed

+350
-0
lines changed

Diff for: CONTRIBUTING.md

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
## How to contribute an implementation (code)?
2+
3+
* Have a look at open issues. They contain the list of algorithms/DS we plan to be implemented. Pick an unassigned issue.
4+
* You can also create a new issue for an algorithm that is not in the list.
5+
* Make sure you are assigned for the issue.
6+
* Code the algorithm/DS following the styleguide defined below.
7+
* Send a PR.
8+
* Be sure to not include any compiled binaries in the patch.
9+
* While sending a PR make sure you follow one issue per PR rule.
10+
11+
12+
<a name="sa"></a>
13+
14+
## Suggesting an algorithm / DS
15+
16+
* First make sure you are not suggesting a duplicate.
17+
* If not, proceed and create the issue. Make sure that you specify only one language in an issue. Create multiple issues for different languages.
18+
* Title of issue should be of the following format -
19+
```
20+
Algorithm/DS Name [Language]
21+
```
22+
* Please include at least one external link for the algorithm/DS in the issue's body for each issue. The link should explain the algorithm/problem/DS in detail.
23+
24+
25+
<a name="cs"></a>
26+
27+
## Code Styleguide
28+
29+
* Code submitted should be modular.
30+
* Don't use global variables.
31+
* Use separate folders for each concept. Folder name should be in full lowercase. If the algorithm/DS name has multiple words, separate them by underscores. (eg `longest_common_subsequence`)
32+
* Filename should be derived from the folder name. (eg `longest_common_subsequence` becomes `longestCommonSubsequence.c` or `LongestCommonSubsequence.java`)
33+
* Name of master function of the code should be kept same as filename to the best extent possible.
34+
* Prefer classes instead of multiple helper functions (where applicable).
35+
* Currently we are accepting contributions in C, C++, C#, Java, Python, Go and JavaScript but other languages may be considered after a discussion.
36+
* Define `tester` code only in `main` routine.
37+
* Use meaningful variable, method and function names and comments.
38+
* No profanity.
39+
* Use external libraries only when no other solution is possible/plausible.
40+
* We have defined [skeleton codes](#samples) for some popular languages below. Please follow them whenever possible.
41+
42+
43+
<a name="points"></a>
44+
45+
## Standalone points
46+
47+
* In some cases, C and C++ implementation will be similar. In that case, only the C implementation must be done.
48+
49+
50+
<a name="improving"></a>
51+
52+
## Improving an implementation
53+
54+
* If you feel you can improve upon an implementation, feel free to open an issue discussing the improvements.
55+
56+
57+
<a name="samples"></a>
58+
59+
## Samples
60+
61+
#### C
62+
63+
```c
64+
void quicksort(int ar_size, int *ar) {
65+
/*
66+
Your implementation here...
67+
*/
68+
}
69+
70+
int main() {
71+
int ar_size = 4, i;
72+
int a[4] = {2, 3, 0, 4};
73+
quicksort(ar_size, a);
74+
75+
for (i=0; i<ar_size; i++){
76+
printf("%d\n", a[i]);
77+
}
78+
return 0;
79+
}
80+
```
81+
82+
#### Python
83+
```python
84+
def quicksort(arr):
85+
#
86+
# Your implementation here...
87+
#
88+
89+
90+
def main():
91+
arr = [2, 3, 0, 4]
92+
sorted_arr = quicksort(arr)
93+
print(sorted_arr)
94+
95+
96+
if __name__ == '__main__':
97+
main()
98+
```
99+
100+
#### Java
101+
```java
102+
public class QuickSort {
103+
104+
static void quickSort(int[] a) {
105+
/*
106+
Your implementation here...
107+
*/
108+
}
109+
110+
public static void main(String[] args) {
111+
int[] arr = new int[] {2, 3, 0, 4};
112+
quickSort(arr);
113+
for(int element: arr) {
114+
System.out.println(element);
115+
}
116+
}
117+
}
118+
```
119+
120+
#### Golang
121+
122+
```go
123+
package main
124+
125+
import "fmt"
126+
127+
// QuickSort sorts an array using QuickSort algorithm
128+
func QuickSort(array []int) []int {
129+
// Your implementation here
130+
return array
131+
}
132+
133+
func main() {
134+
array := []int{2, 3, 0, 4}
135+
sortedArray := QuickSort(array)
136+
fmt.Println(sortedArray)
137+
}
138+
```
139+
140+
#### JavaScript
141+
142+
```JavaScript
143+
function quickSort (arr) {
144+
/*
145+
Your implementation here
146+
*/
147+
}
148+
149+
function main () {
150+
let input = [2, 3, 0, 4];
151+
quickSort(input);
152+
for (let x in input) {
153+
console.log(input[x] + ' ');
154+
}
155+
}
156+
157+
main();
158+
```
159+
160+
#### C#
161+
162+
```csharp
163+
using System;
164+
165+
public class QuickSort
166+
{
167+
public static void DoQuickSort(int[] a)
168+
{
169+
/*
170+
Your implementation here...
171+
*/
172+
}
173+
174+
public static void Main()
175+
{
176+
int[] arr = new int[] {2, 3, 0, 4};
177+
DoQuickSort(arr);
178+
foreach(int element in arr)
179+
{
180+
Console.Write(element + " ");
181+
}
182+
Console.WriteLine("");
183+
}
184+
}
185+
```

Diff for: README.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Algos
2+
3+
Community (college) maintained list of Algorithms and Data Structures implementations.
4+
5+
6+
7+
## Implemented Algorithms
8+
9+
10+
| Algorithm | C | CPP | Java | Python | Golang | JavaScript | C# |
11+
|:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:| :-----------------:|
12+
| [Bin Sort](http://www.cdn.geeksforgeeks.org/bucket-sort-2/)| | | | | | | |
13+
| [Binary Search](https://en.wikipedia.org/wiki/Binary_search_algorithm) | | | | | | | |
14+
| [Breadth First Search](https://en.wikipedia.org/wiki/Breadth-first_search) | | | | | | | |
15+
| [Breadth First Traversal](https://www.cs.bu.edu/teaching/c/tree/breadth-first/) | | | || | | |
16+
| [Coin Change Problem](http://www.algorithmist.com/index.php/Coin_Change) | | | | | | | |
17+
| [Counting Sort](http://www.geeksforgeeks.org/counting-sort/)| | | | | | | |
18+
| [Depth First Traversal](http://www.geeksforgeeks.org/depth-first-traversal-for-a-graph/) | | | | | | | |
19+
| [Dijkstra Algorithm](https://en.wikipedia.org/wiki/Dijkstra's_algorithm) | | | | | | | |
20+
| [Euclidean GCD](https://en.wikipedia.org/wiki/Euclidean_algorithm) | | | | | | | |
21+
| [Exponentiation by Squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) | | | | | | | |
22+
| [Heap Sort](https://en.wikipedia.org/wiki/Heapsort) | | | | | | | |
23+
| [Insertion Sort](https://en.wikipedia.org/wiki/Insertion_sort) | | | | | | | |
24+
| [k-NN](https://en.wikipedia.org/wiki/K-nearest_neighbors_algorithm) | | | | | | | |
25+
| [Largest Sum Contiguous Subarray](http://www.geeksforgeeks.org/largest-sum-contiguous-subarray/) | | | | | | | |
26+
| [Linear Regression](https://en.wikipedia.org/wiki/Linear_regression) | | | | | | | |
27+
| [Linear Search](https://en.wikipedia.org/wiki/Linear_search) | | | || | | |
28+
| [Longest Common Subsequence](http://www.geeksforgeeks.org/dynamic-programming-set-4-longest-common-subsequence) | | | | | | | |
29+
| [Longest Palindromic Substring](http://www.geeksforgeeks.org/longest-palindrome-substring-set-1/) | | | | | | | |
30+
| [Merge Sort](https://www.khanacademy.org/computing/computer-science/algorithms/merge-sort/a/overview-of-merge-sort) | | | | | | | |
31+
| [Modular Exponential](http://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/) | | | | || | |
32+
| | | | | | | | |
33+
| [Prime Factor](https://en.wikipedia.org/wiki/Prime_factor) | | | | | | | |
34+
| [Prims](https://en.wikipedia.org/wiki/Prim%27s_algorithm) | | | | | | | |
35+
| [Quick Select](https://en.wikipedia.org/wiki/Quickselect) | | | | | | | |
36+
| [Quicksort](https://en.wikipedia.org/wiki/Quicksort) | | | | | | | |
37+
| [Radix Sort](http://www.geeksforgeeks.org/radix-sort/) | | | | | | | |
38+
| [Rod Cutting Problem](http://www.geeksforgeeks.org/dynamic-programming-set-13-cutting-a-rod/) | | | | | | | |
39+
| [Shell Sort](https://en.wikipedia.org/wiki/Shellsort) | | | | | | | |
40+
| [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) | | | | | | | |
41+
| [Sleep Sort](http://www.geeksforgeeks.org/sleep-sort-king-laziness-sorting-sleeping/) | | | | | | | | |
42+
43+
44+
## Implemented Data Structures
45+
46+
| Data Structure | C | CPP | Java | Python | Golang | JavaScript | C# |
47+
|:--------------|:----------------:|:----------------:|:----------------:|:-----------------:|:-----------------:|:-----------------:|:-----------------:|
48+
| [AVL Tree](http://www.geeksforgeeks.org/avl-tree-set-1-insertion)|| | | | | | |
49+
| | | | | | | | |
50+
| [Linked List](https://en.wikipedia.org/wiki/Linked_list) | | | | | | | |
51+
| [Queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) | | | | | | | |
52+
| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | | | | | | | |
53+
| [Trie](https://en.wikipedia.org/wiki/Trie) | | | | | | | | |
54+
| [Queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) | | | | | | | | |
55+
56+
57+
58+
## How to run them
59+
60+
| Language | Steps |
61+
|:--------------|:----------------|
62+
| C |<pre>gcc [filename.c]<br>./a.out # unix<br>a.exe # windows</pre>|
63+
| CPP |<pre>g++ [filename.cpp]<br>./a.out # unix<br>a.exe # windows</pre>|
64+
| Java |<pre>javac [filename.java]<br>java [filename]</pre>|
65+
| Python |<pre>python [filename.py]</pre>|
66+
| Golang |<pre>go run [filename.go]</pre>|
67+
| JavaScript |<pre>node [filename.js]</pre>|
68+
| C# |<pre>mcs [filename.cs]<br/>mono [filename.exe]</pre>|
69+
70+
71+
## Resources
72+
73+
* [Algorithms - Learneroo](https://www.learneroo.com/subjects/8)
74+
* [Awesome-Algorithms](https://github.com/tayllan/awesome-algorithms)
75+
* [Algorithms List - GeeksforGeeks](http://www.geeksforgeeks.org/fundamentals-of-algorithms/)
76+
* [Intro to Algorithms - Khan Academy](https://www.khanacademy.org/computing/computer-science/algorithms)
77+
* [Popular Data Structures and Algorithms - Codechef](https://discuss.codechef.com/questions/48877/data-structures-and-algorithms)
78+
* [Stanford-ACM-Codes](https://github.com/jaehyunp/stanfordacm) - A list of codes written by previous Stanford ACM team members and coaches.
79+
* [Data Structures and Algorithms](https://hackr.io/tutorials/learn-data-structures-algorithms) - A user ranked list of online tutorials to learn Data Structures and Algorithms online.
80+
81+
82+
83+
## Contributing
84+
85+
See [CONTRIBUTING.md](CONTRIBUTING.md).
86+
87+
If you plan to suggest a new algorithm or DS, please make sure to read [the guidelines](CONTRIBUTING.md#sa).
88+
89+
90+
## Credits
91+
92+
Idea by [@RavinduSachintha](https://github.com/RavinduSachintha)
93+
94+
95+
## Project Maintainers
96+
97+
* [RavinduSachintha](https://github.com/RavinduSachintha)
98+
* [Danushka Herath](https://github.com/danushka96)
99+
* [Asitha Indrajith](https://github.com/AsithaIndrajith)
100+
* [Sachintha Rathnayake](https://github.com/Sacheerc)
101+
102+
Only project maintainers should merge a PR. Other members can add their reviews to a PR but the merging should be done by only a project maintainer.

Diff for: bubble_sort/bubbleSort.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.util.Scanner;
2+
3+
class bubbleSort{
4+
public static void main(String a[]){
5+
6+
Scanner sc=new Scanner(System.in);
7+
System.out.print("Size of array :");
8+
int n=sc.nextInt();
9+
10+
int[] num=new int[n];
11+
int i,j,tmp;
12+
13+
for(i=0;i<n;i++){
14+
num[i]=sc.nextInt();
15+
}
16+
17+
for(i=0;i<n;i++){
18+
for(j=0;j<(n-i);j++){
19+
if(j==(n-1)){
20+
break;
21+
}
22+
else{
23+
if(num[j]>num[j+1]){
24+
tmp=num[j];
25+
num[j]=num[j+1];
26+
num[j+1]=tmp;
27+
}
28+
}
29+
}
30+
}
31+
for(i=0;i<n;i++){
32+
System.out.print(num[i]+" " );
33+
}
34+
}
35+
}

Diff for: stack/stack.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Implementing the Stack class
2+
# This is Complete
3+
4+
5+
class Stack:
6+
def __init__(self):
7+
self.items = []
8+
9+
def isEmpty(self):
10+
return self.items == []
11+
12+
def push(self, ele):
13+
self.items.append(item)
14+
15+
def pop(self):
16+
return self.items.pop()
17+
18+
def peek(self):
19+
return self.items[len(self.items) - 1]
20+
21+
def size(self):
22+
return len(self.items)
23+
24+
def printStack(self):
25+
print(self.items)
26+
27+
# ///// End of Stack class
28+

0 commit comments

Comments
 (0)