?? gensortrand.c
字號:
/*
This program is designed to be built into a DLL and called from LabVIEW. Each function
that is marked DLLEXPORT can be called from third party code. These functions are
identical to the generate and sort example.
*/
#include <ansi_c.h> // includes the ansi_c and windows libraries
#include <windows.h>
int __stdcall DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{ // main DLL function
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 DLLEXPORT generateRand(int *iArray, int ARRAYSIZE)
{
int i, sTime;
time(&sTime); // gets time to seed the random number
for (i=0;i<ARRAYSIZE;i++)
{
srand(sTime*100+i*10); // seeds each random from an offset of the time
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 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 + -