What will be the order of the following array after three it
What will be the order of the following array after \'three\' iterations (sorting in ascending order) of: [CLO-2] 29, 80, 5, 12, 34, 56, 21, 55, 20 write a function that will sort data in ascending order using selection sort. Also write its call from main [CLO-3]
Solution
a)
Using Bubble Sort (AFtr 3 iterations) : 5, 12, 29, 34, 21, 55, 20, 56, 80
Using Selection Sort (Aftr 3 iterations ): 5, 12, 20, 80, 34, 56, 21, 55, 29
b)
void selectionSort(int list[], int length)
{
int min,loc,temp;
for(int i=0;i<length;i++)
{
min=list[i];
loc=i;
for(int j=i+1;j<length;j++)
{
if(min>list[j])
{
min=list[j];
loc=j;
}
}
temp=list[i];
list[i]=list[loc];
list[loc]=temp;
}
}
/// Man
int main()
{
int arr1[] = {29, 80, 5, 12, 34,56,21,55,20};
selectionSort(arr1,9);
for(int i=0;i<9;i++) cout <<arr1[i]<<\" \";
}
![What will be the order of the following array after \'three\' iterations (sorting in ascending order) of: [CLO-2] 29, 80, 5, 12, 34, 56, 21, 55, 20 write a fun What will be the order of the following array after \'three\' iterations (sorting in ascending order) of: [CLO-2] 29, 80, 5, 12, 34, 56, 21, 55, 20 write a fun](/WebImages/44/what-will-be-the-order-of-the-following-array-after-three-it-1139603-1761610900-0.webp)