From 26dcec1c52af95628b971c64c01fd6676454f181 Mon Sep 17 00:00:00 2001 From: Afroz Chakure Date: Mon, 21 Oct 2019 21:21:23 +0530 Subject: [PATCH 1/2] Added my name to BeerBottles.txt --- Challenge 1/BeerBottles.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Challenge 1/BeerBottles.txt b/Challenge 1/BeerBottles.txt index 9dbe487..c56a3d4 100644 --- a/Challenge 1/BeerBottles.txt +++ b/Challenge 1/BeerBottles.txt @@ -73,7 +73,7 @@ Pass it around Take one down, Pass it around ------------------------------------------------------------- -84 bottles of beer on the wall by +84 bottles of beer on the wall by afrozchakure 84 bottles of beer. Take one down, Pass it around From 9b9c0552267b6646a445bc2495bec3ef820f9918 Mon Sep 17 00:00:00 2001 From: Afroz Chakure Date: Mon, 21 Oct 2019 21:26:19 +0530 Subject: [PATCH 2/2] Added Code for selectionsort.c --- Challenge 2/selectionsort.c | 49 ++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Challenge 2/selectionsort.c b/Challenge 2/selectionsort.c index 38dc7a3..d2ba340 100644 --- a/Challenge 2/selectionsort.c +++ b/Challenge 2/selectionsort.c @@ -1,2 +1,49 @@ //Link: https://www.geeksforgeeks.org/selection-sort/ -//Add your code after this comment line. \ No newline at end of file +//Add your code after this comment line. + +#include + +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +void selectionSort(int arr[], int n) +{ + int i, j, min_idx; + + // One by one move boundary of unsorted subarray + for (i = 0; i < n-1; i++) + { + // Find the minimum element in unsorted array + min_idx = i; + for (j = i+1; j < n; j++) + if (arr[j] < arr[min_idx]) + min_idx = j; + + // Swap the found minimum element with the first element + swap(&arr[min_idx], &arr[i]); + } +} + +/* Function to print an array */ +void printArray(int arr[], int size) +{ + int i; + for (i=0; i < size; i++) + printf("%d ", arr[i]); + printf("\n"); +} + +// Driver program to test above functions +int main() +{ + int arr[] = {64, 25, 12, 22, 11}; + int n = sizeof(arr)/sizeof(arr[0]); + selectionSort(arr, n); + printf("Sorted array: \n"); + printArray(arr, n); + return 0; +}