冒泡排序 #include "pch.h"
#include<stdlib.h>
#include<windows.h>
#include <iostream>
using namespace std;
int arr[1000];
int len = 1000;
void Value()
{
for (int i = 0; i < len; i++)
{
arr[i] = rand() % 30000;
}
}
void Bubble_Sort(int *arr, int len)
{
int i, j, exchange;
for (int i = 0; i < len-1; i++)
{
for (int j = 0; j < len - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
exchange = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = exchange;
}
}
}
}
void print()
{
for (int k = 0; k < len; k++)
{
cout << arr[k] << " ";
}
}
int main()
{ long t1 = GetTickCount();
Value();
Bubble_Sort(arr, len);
long t2 = GetTickCount();
print();
long t3 = GetTickCount();
cout << "运行时间:(不包含输出)" << (t2 - t1) << endl;
cout << "运行时间:" << (t3 - t1) << endl;
return 0;
}