From 29dac9385acabc36b684359b36d7160e7f437a46 Mon Sep 17 00:00:00 2001 From: ishaan0030 <56684565+ishaan0030@users.noreply.github.com> Date: Thu, 17 Oct 2019 19:56:09 +0530 Subject: [PATCH] bubble_sort.css --- components/components/bubble_sort.css | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 components/components/bubble_sort.css diff --git a/components/components/bubble_sort.css b/components/components/bubble_sort.css new file mode 100644 index 0000000..92a27ac --- /dev/null +++ b/components/components/bubble_sort.css @@ -0,0 +1,40 @@ +// C program for implementation of Bubble sort +#include + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + + +void bubbleSort(int arr[], int n) +{ + int i, j; + for (i = 0; i < n-1; i++) + + // Last i elements are already in place + for (j = 0; j < n-i-1; j++) + if (arr[j] > arr[j+1]) + swap(&arr[j], &arr[j+1]); +} + +void printArray(int arr[], int size) +{ + int i; + for (i=0; i < size; i++) + printf("%d ", arr[i]); + printf("\n"); +} + + +int main() +{ + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + printf("Sorted array: \n"); + printArray(arr, n); + return 0; +}