Sort-insertion sort-direct insertion sort

direct insertion sort

Straight Insertion Sort (Straight Insertion Sort) is the simplest sorting method. The basic operation is to directly insert a record into an already sorted ordered sequence list, thereby obtaining a new sorted sequence with the number of records increased by 1. surface.

Algorithm ideas

For example, when playing cards, the order of the cards dealt to the hand is as follows, and the insertion method is used for sorting.
Insert image description here
Simulate hand calculation
Insert image description here

Algorithm implementation

  1. Implemented without sentinels
    Insert image description here
void InsertSort(int A[],int n){
   
    
    
    int i,j,temp;
    for ( i = 1; i < n

Guess you like

Origin blog.csdn.net/QQ657205470/article/details/127426836