

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The implementation and function calls for selection sort and bubble sort algorithms. The selection sort algorithm finds the index of the smallest value in a given range, while bubble sort swaps adjacent elements if they are in the wrong order. Both algorithms are essential in computer science for sorting data.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Algorithms for Selection Sort and Bubble Sort from p 401 of textbook, modified find and return the index of the smallest value in the array within the given range int get_max_range( char list[ ], /* the array we are looking in / int first, / the index of the first element we will look at / int last ) / the index of the last element we will look at */ index_of_max = first for each value of i from first+1 to last if list[i] is greater than list[index_of_max] update index_of_max to i return index_of_max
void select_sort ( char list[ ],/* list to be sorted / int n ) / number of elements / int to_fill / subscript of last element of unsorted array/ char temp /temporary storage / index_of_max /index of greatest element in unsorted array */ for to_fill = n- 1 (whole array unsorted) down to to_fill = 1 (last 2 elements need to be put in order) Find position of greatest element in unsorted array. Swap it with the element at end of unsorted array.