第1个回答 2011-06-15
随机数产生的公式为 =100+int(rand()*900)
假设产生在A1:A100中,在B1:B100中排序
升序:B1公式 =small(a$1:a$100,row()) 公式下拉
降序:B1公式 =large(a$1:a$100,row()) 公式下拉
第2个回答 2011-06-22
#include<iostream>
#include<cstdlib>
#include<time.h>
#include<iomanip>
using namespace std;
void BubbleSort(int r[], int n)
{
int temp;
int exchange;
int bound;
exchange=n-1; //第一趟起泡排序的范围是r[0]到r[n-1]
while (exchange) //仅当上一趟排序有记录交换才进行本趟排序
{
bound=exchange;
exchange=0;
for (int j=0; j<bound; j++) //一趟起泡排序
if (r[j]>r[j+1])
{
temp=r[j];
r[j]=r[j+1];
r[j+1]=temp;
exchange=j; //记录每一次发生记录交换的位置
}
}
}
int Partition(int r[], int first, int end)
{
int i=first; //初始化
int j=end;
int temp;
while (i<j)
{
while (i<j && r[i]<= r[j])
j--; //右侧扫描
if (i<j)
{
temp=r[i]; //将较小记录交换到前面
r[i]=r[j];
r[j]=temp;
i++;
}
while (i<j && r[i]<= r[j])
i++; //左侧扫描
if (i<j)
{
temp=r[j];
r[j]=r[i];
r[i]=temp; //将较大记录交换到后面
j--;
}
}
return i; //i为轴值记录的最终位置
}
//快速排序
void QuickSort(int r[], int first, int end)
{
if (first<end)
{ //递归结束
int pivot=Partition(r, first, end); //一次划分
QuickSort(r, first, pivot-1);//递归地对左侧子序列进行快速排序
QuickSort(r, pivot+1, end); //递归地对右侧子序列进行快速排序
}
}
void get(int a[],int b[],int n)//获取 100~999之间的随机数
{
srand(time(0));
for(int i=0;i<n;i++)
{
a[i]=rand()%900+100;
b[i]=rand()%900+100;
}
}
int main()
{
int n=100;
int a1[100]={0};
int a2[100]={0};
get(a1,a2,n);
for(int i=0;i<n;i++) //查看获取的随机数
cout<<a1[i]<<' ';
cout<<endl;
for(int i=0;i<n;i++)
cout<<a2[i]<<' ';
cout<<endl;
QuickSort(a1, 0, n-1);
for(int i=0;i<n;i++)//输出快速排序后的数组
cout<<a1[i]<<' ';
cout<<endl;
BubbleSort(a2, n);
for(int i=0;i<n;i++)//输出冒泡排序后的数
cout<<a2[i]<<' ';
cout<<endl;
return 0;
}
我是用c++写的,不知道是否可以帮到你