⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gensortrand.c

📁 labview实例
💻 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 + -