int main()
{
	int N;
	ElementType *A;

	scanf("%d", &N);
	A = (ElementType *)malloc(N * sizeof(ElementType));
	Read( A, N );
	MySort( A, N );
	PrintA( A, N );
	return 0;
}
Esempio n. 2
0
/*********************************************************************************\
从考试成绩中划出及格线
10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如下:
(1) 及格线是10的倍数;
(2) 保证至少有60%的学生及格;
(3) 如果所有的学生都高于60分,则及格线为60分
\*********************************************************************************/
int PassLine(float score[], size_t n)
{
	int pl(0);
	MySort(score, n);
	for (size_t i = 0; i<n; ++i){
		std::cout << score[i] << ' ';
	}
	std::cout << std::endl;
	pl = score[int(n*(1 - 0.6) - 1)];
	pl = (int(pl / 10)) * 10;
	if (pl<int(score[int(n*(1 - 0.6))])){
		pl = int(int(score[int(n*(1 - 0.6))]) / 10) * 10;
	}
	if (score[0]>60) pl = 60;
	return pl;
}
DWORD WINAPI MyThreadProc1(LPVOID lpParameter)
{
	while(true)
	{

		WaitForSingleObject(hMutex,INFINITE);

		int			DouNums1;							//数据块共有多少个浮点数
		unsigned	int Length1 = 0;					//数据块的长度,总字节数
		char *		DataBuf1 = new char[DataBlock];		//数据块缓冲区
		double *	DouBuf1 = new double[MaxSizeDou];	//数据块双精度浮点数数组
		char *		Buffer1 = new char[MyBufferSize];


		while(!(feof(InFile))){
			
				//线程1的读排写
				if((Length1 = fread(DataBuf1, sizeof(char), DataBlock - 20, InFile)) < DataBlock - 20){

					ReleaseMutex(hMutex);

					DataBuf1[Length1] = '\0';

					DouNums1 = Str2Dou(DataBuf1, DouBuf1);

					MySort((RadixData*)DouBuf1, DouNums1);

					if(FileCount == 0){

						FILE * OutFile = NULL;
						OutFile = fopen(OutFileName, "wb");

						int LengthTemp, LengthOutPut = 0;
						for(int i = 0; i < DouNums1; i++){

							LengthTemp = Dou2Str(Buffer1 + LengthOutPut, DouBuf1[i]);
							LengthOutPut += LengthTemp;

						}
						fwrite(Buffer1, 1, LengthOutPut, OutFile);	//将整块字符串fwrite到输出文件

						fclose(OutFile);

						FileCount++;
					
					}
					else{

						char * FileName = TempFileName(FileCount++);

						FILE *TempFile = fopen(FileName, "wb");
						free(FileName);
						WriteData(TempFile, DouBuf1, DouNums1);

						fclose(TempFile);
					
					}

				}
				else{

					char * p = DataBuf1 + Length1 - 1;
					int i = 0;

					while(*p != '\n' && *p != '\0'){
						fread(DataBuf1 + Length1 + i, 1, 1, InFile);
						p++;
						i++;
					}
					DataBuf1[Length1 + i] = '\0';

					DouNums1 = Str2Dou(DataBuf1, DouBuf1);

					ReleaseMutex(hMutex);

					MySort((RadixData*)DouBuf1, DouNums1);

					char * FileName = TempFileName(FileCount++);

					FILE *TempFile = fopen(FileName, "wb");
					free(FileName);
					WriteData(TempFile, DouBuf1, DouNums1);

					fclose(TempFile);

				}
		}

		delete []DataBuf1;
		delete []DouBuf1;
		delete []Buffer1;
		break;

	}

	flag1 = true;
	return 0;

}