diff --git a/Order Of Programs.md b/Order Of Programs.md index 965955e..9d4da17 100644 --- a/Order Of Programs.md +++ b/Order Of Programs.md @@ -28,4 +28,5 @@ |26 | ArrayReverse.c | ArrayReverse.exe | WAP to print out an array of dynamic values in reverse order | |27 | BubbleSort.c | BubbleSort.exe | WAP to sort an array using bubble sort | |28 | LinearSearch.c | LinearSearch.exe | WAP to search an element in an array using Linear Search | -|29 | BinarySearch.c | BinarySearch.exe | WAP to search an element in an array using Binary Search | \ No newline at end of file +|29 | BinarySearch.c | BinarySearch.exe | WAP to search an element in an array using Binary Search | +|30 | SelectionSort.c | SelectionSort.exe | WAP to sort an array using selection sort | \ No newline at end of file diff --git a/SelectionSort.c b/SelectionSort.c new file mode 100644 index 0000000..f818583 --- /dev/null +++ b/SelectionSort.c @@ -0,0 +1,38 @@ +// WAP to sort an array using selection sort. + +void swap(int *xp, int *yp) { + int temp = *xp; + *xp = *yp; + *yp = temp; +} + +void main() { + int a[10], n, min, i, j; + + // To set range of array: + printf("\n Enter the range of array: \n"); + scanf("%d", &n); + + // To get values of array: + printf("\n Enter the elements of the array: \n"); + for (i=0 ; i<=n; i++) { + scanf("%d", &a[i]); + } + + // Selection Sort Algorithm: + for (i=0; i