📄 sortbig.c
字号:
#include <stdlib.h>
#include <time.h> //for the seedrnd() function
#include <stdio.h>
#define SIZE 10000 //size of the array
void sort(int *array,int size);
int rnd(int range);
void seedrnd(void);
void main()
{
int r[SIZE];
int i;
printf("Here is the array unsorted:\n");
seedrnd(); //seed the randomizer
for(i=0;i<SIZE;i++)
{
r[i] = rnd(1000)+1;
printf("%i\t",r[i]);
}
printf("\nPress Enter to see the sorted array:");
getchar();
printf("\n");
sort(r,SIZE);
for(i=0;i<SIZE;i++)
printf("%i\t",r[i]);
}
void sort(int *array,int size)
{
int a,b,temp;
for(a=0;a<size-1;a++)
for(b=a+1;b<size;b++)
if(array[a] > array[b])
{
temp=array[b];
array[b] = array[a];
array[a] = temp;
}
}
int rnd(int range)
{
int r;
r=rand()%range; //spit up random num.
return(r);
}
/* Seed the randomizer */
void seedrnd(void)
{
srand((unsigned)time(NULL));
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -