?? gensort.cpp
字號:
// GenSort.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include <stdlib.h>
#include <time.h>
extern "C" void __declspec(dllexport) generateRand(int *iArray, int ARRAYSIZE);
extern "C" void __declspec(dllexport) bubbleSort(int *iArray, int ARRAYSIZE);
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
/*
The purpose of this function is to generate an array of random numbers of the size
ARRAYSIZE. Each number will be an integer between 0 and 100. The numbers are seeded
by time plus an offset. The array is passed into this function by reference
*/
void __declspec(dllexport) generateRand(int *iArray, int ARRAYSIZE)
{
long int i;
time_t sTime;
time(&sTime); // gets time to seed the random number
srand((unsigned int)sTime*100); // seeds each random from an offset of the time
for (i=0;i<ARRAYSIZE;i++)
{
iArray[i]=rand()*100/RAND_MAX; // inserts the random number into the array
}
}
/*
The purpose of this function is to sort an array of random numbers. This function
uses the bubblesort algorithm, which has the time complexity O(n^2). The array
is passed into this function by reference.
*/
void __declspec(dllexport) bubbleSort(int *iArray, int ARRAYSIZE)
{
int holder, x, y;
for(x = 0; x < ARRAYSIZE; x++)
{
for(y = 0; y < ARRAYSIZE-1; y++)
{
if(iArray[y] > iArray[y+1])
{ // compares neighboring elements and swaps if necessary
holder = iArray[y+1];
iArray[y+1] = iArray[y];
iArray[y] = holder;
}
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -