selection and insertion sort

Completion of blue ink cloud selection and insertion sort

Question: Using selection and insertion sort, write the result of the third sort: 3 1 9 3 6 2 10.

selection sort

Problem solving ideas

  • For 3 1 9 3 6 2 10, use selection sort

  • Summary: I think selection sort is to scan from left to right in a list, encounter the smallest, swap it with the first number, and then start from the second number, continue to repeat the above operation, constantly Find the smallest, and finally it becomes an ordered arrangement.

  • For 3 1 9 3 6 2 10, use insertion sort

  • Summary: I think insertion sort is in a list, first determine the order of the first two, fix it, compare the third number with the second number, if it is large, do not move, if it is small, insert it into the previous list In the corresponding position, then the order of the first three numbers remains unchanged, the fourth number is compared with the third, and the inserted position is inserted.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325061556&siteId=291194637
Recommended