Array data type, used in a programming language to specify a variable that can be indexed
During my experiment with array / hash variable, i’ve found this interesting website. The wiki explains how to sort the integers in the array by using a variety of languages. even some programming languages that I do not know at all.
I’ll pick a few examples of sorting functions described in the wiki
Sort an integer array using C language:
#include <stdlib.h> /* qsort() */
#include <stdio.h> /* printf() */
int intcmp(const void *aa, const void *bb)
{
const int *a = aa; *b = bb;
return (*a < *b) ? -1 : (*a > *b);
}
int main()
{
int nums[5] = {2,4,3,1,2};
qsort(nums, 5, sizeof(int), intcmp);
printf("result: %d %d %d %d %d\n",
nums[0], nums[1], nums[2], nums[3], nums[4]);
return 0;
}
Follow me on Twitter