Skip to content
This repository was archived by the owner on Jun 26, 2022. It is now read-only.

Commit 48fa9b4

Browse files
authored
Create gariya_bubbleSort.c
gariya_bubbleSort.c
1 parent 32ba621 commit 48fa9b4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

java/gariya_bubbleSort.c

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Java program for implementation of Bubble Sort
2+
class BubbleSort
3+
{
4+
void bubbleSort(int arr[])
5+
{
6+
int n = arr.length;
7+
for (int i = 0; i < n-1; i++)
8+
for (int j = 0; j < n-i-1; j++)
9+
if (arr[j] > arr[j+1])
10+
{
11+
// swap arr[j+1] and arr[j]
12+
int temp = arr[j];
13+
arr[j] = arr[j+1];
14+
arr[j+1] = temp;
15+
}
16+
}
17+
18+
/* Prints the array */
19+
void printArray(int arr[])
20+
{
21+
int n = arr.length;
22+
for (int i=0; i<n; ++i)
23+
System.out.print(arr[i] + " ");
24+
System.out.println();
25+
}
26+
27+
// Driver method to test above
28+
public static void main(String args[])
29+
{
30+
BubbleSort ob = new BubbleSort();
31+
int arr[] = {64, 34, 25, 12, 22, 11, 90};
32+
ob.bubbleSort(arr);
33+
System.out.println("Sorted array");
34+
ob.printArray(arr);
35+
}
36+
}
37+
/* This code is contributed by Rajat Mishra */

0 commit comments

Comments
 (0)