Unverified Commit 02053e29 authored by Lokesh Singh's avatar Lokesh Singh Committed by GitHub

Update bubble sort

parent 78cb4256
void swap(int *xp, int *yp)
//cpp funtion for sorting using bubble sort
//
void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
......@@ -17,3 +19,26 @@ void swap(int *xp, int *yp)
}
}
}
//
//java funtion
public static void bubbleSort(int arr[], int n)
{
//code here
int i, j;
//Traversing over the array.
for (i = 0; i < n-1; i++)
{
//Last i elements are already in place so we do not include them.
for (j = 0; j < n-i-1; j++)
if(arr[j] > arr[j+1])
{
//Swapping, if the element at current index is greater
// than the next element.
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment