Insertion Sort Write a c program to do the following activities:
a) Define a function to read at least 30 integer data from user.
b) Define a function to put this user-given data in ascending order using the insertion-sort algorithm. And display the list. c) Define a function to display the contents of this list in reverse order.
Answers
Answered by
0
Answer:
insertion-sort
Another Example:
12, 11, 13, 5, 6
Let us loop for i = 1 (second element of the array) to 4 (last element of the array)
i = 1. Since 11 is smaller than 12, move 12 and insert 11 before 12
11, 12, 13, 5, 6
i = 2. 13 will remain at its position as all elements in A[0..I-1] are smaller than 13
11, 12, 13, 5, 6
i = 3. 5 will move to the beginning and all other elements from 11 to 13 will move one position ahead of their current position.
5, 11, 12, 13, 6
i = 4. 6 will move to the position after 5, and elements from 11 to 13 will move one position ahead of their current position.
5, 6, 11, 12, 13
Explanation:
pls, mark me as the brainliest.
Similar questions