Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sort the following list using the selection sort algorithm as discussed in this

ID: 3683803 • Letter: S

Question

Sort the following list using the selection sort algorithm as discussed in this chapter. Show the list after each iteration of the outer for loop. 6, 45, 10, 25, 58, 2, 50, 30, 86 Given the declaration: char stringl5[16]; Mark the following statements at valid or invalid. If a statement is invalid, explain why. Given the declaration: char name(8] - "Shelly"; Mark the following statements as "Yes" if they output Shelly. Otherwise, mark the statement as "No** and explain why it does not output Shelly.

Explanation / Answer

// C program for implementation of selection sort
#include <stdio.h>

void swap(int *xp, int *yp)
{
int temp = *xp;
*xp = *yp;
*yp = temp;
}

/* Function to print an array */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
printf("%d ", arr[i]);
printf(" ");
}

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]);
printArray(arr, n);
}
}


// Driver program to test above functions
int main()
{
int arr[] = {6, 45, 10, 25, 58, 2, 50, 30, 86};
int n = sizeof(arr)/sizeof(arr[0]);
selectionSort(arr, n);
printf("Sorted array: ");
printArray(arr, n);
return 0;
}

question 2:

T

T

F (assignment does not happen this way, you have to use strcpy)

T

T

T

T

question 3:

every option will output Shelly

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote