Pointer selection sorting, 10 integers sorted from small to large

Source: Internet
Author: User

//pointer method, select Sort method for 10 int by small to large arrangement#include <stdio.h>Main () {intn=Ten, i,b,a[Ten],*p; intSortint*q,intN); //scanf ("%d", &10);    for(p=a;p<a+Ten;p + +)//keyboard input array elementsscanf"%d", p); P=a;//Super Important!!!!!!!!!! Can't forgetSort (p,Ten);//calling Functions        for(p=a;p<a+Ten;p + +)//functions after the output sortprintf"%3d",*p);}intSortint*q,intN) {    int*p,i,*j,*k,t;  for(k=q;k<q+9; k++) {p=K;  for(j=p+1; j<q+Ten; j + +)          if(*p>*j) P=J; //*k=*p;t=*K; *k=*p; *p=T; }}

This pointer function is completely self-revision change to complete independently, feel this period of time progress is very big, satisfied!

Remember the idea of sorting, sorting sub-function, reset a pointer variable p, the address of K is assigned to P, is because the address of the J to be assigned to P, and not directly assigned to K, because K is the outside of the loop variable for the loop, can not arbitrarily assign value, will be confused!!

In the main function, before calling the sort function, be sure to reassign p to a (that is, a[0]), because the previous input loop, p already points to the address of a[9].

Pointer selection sorting, 10 integers sorted from small to large

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.