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