C language pointer exercise-Direct insertion sorting

Source: Internet
Author: User
# Include <stdio. h>
Void print_result (float *, INT );
Void insert_sort (float *, INT );


Int main ()
{
Int I;
Float array [10];
Float * pointer;
Printf ("Enter 10: \ n ");
For (I = 0; I <10; I ++)
{
Scanf ("% F", & array [I]);
}
Pointer = array;
Insert_sort (pointer, 10 );
Print_result (pointer, 10 );


Return 0;
}

Void print_result (float * P, int N)
{// Output result
Int K;
For (k = 0; k <n; k ++)
{
Printf ("% G \ t", * (p + k ));
}
}

Void insert_sort (float * PT, int N)
{// Direct insertion sorting method with all pointers
Int I, J;
Float tempnum;

For (I = 1; I <n; I ++ ){
For (j = 0; j <I; j ++)
{
If (* (Pt + J) <* (Pt + I ))
{
Tempnum = * (Pt + I );
* (Pt + I) = * (Pt + J );
* (Pt + J) = tempnum;
}
}

}
}

Configure a previous image and code

/// ======================================
Void insertsort (INT arr [], int N)
{
Printf ("\ n direct insertion sorting process: \ n ");
Int I, j, T;
For (I = 1; I <n; I ++)
{
For (j = 0; j <I; j ++)
{
If (ARR [J]> arr [I])
{
T = arr [I];
Arr [I] = arr [J];
Arr [J] = T;
}
}
Int L = 0;
For (; L <n; l ++ ){
Printf ("% 3C", arr [l]);
}
Printf ("\ n ");

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.