C to sort the elements in an array

Source: Internet
Author: User

Use C to sort the elements in the array so that the elements in the array are arranged from small to large. Just a little bit of a problem in this process, in the digital Exchange in C, you must use pointers, you cannot use references. In a later article, I'm going to learn the difference between a reference and a pointer in C. Let's take a look at my code below.

#include <stdio.h>voidSwapint*a,int*B);voidRestintLels[],intcount);/** * This instance is used to implement the ordering of the array of user input * The elements in the array are required from small to large @brief main * @return  */intMainvoid){/** i **/for loop traversal    inti =0;/** is used to store the number of elements in an array **/    intNum printf"Please enter the number of the array:\n"); scanf"%d", &num);//Gets the number of array elements entered by the user    /** the array used to store user input **/    intArray[num]; printf"Please enter the element of the array:\n"); for(i =0; i < num;i++) scanf ("%d", &array[i]); Rest (Array,num);//To sortprintf"The array after rest:\n"); for(i =0; i < num;i++) printf ("%d\t", Array[i]);return 0;}/** * @brief swap is used to exchange element A and element b for * @param A number to be exchanged a * @param b number to be exchanged B */voidSwapint*a,int*B) {inttemp = *a;    *a = *b; *b = temp;}/** * @brief Rest is used to sort the array, from small to large * @param lels to be sorted * @param Count of the number of array elements ordered */voidRestintLels[],intCount) {/** temporarily using bubble sort **/    /** Temporary variable i,j **/    intI,j; for(i =0; I < count-1; i++) { for(j = i+1; J < count;j++) {if(Lels[i] > Lels[j]) swap (&lels[i],&lels[j]); }    }}

C to sort the elements in an array

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.