# 帮小弟我看看一个排序有关问题(5)

www.MyException.Cn  网友分享于：2013-03-08  浏览：18次

int nIntegerNumber[INTEGER_NUMBER];
char cString[STRING_LENGHT];
char cTempChar[SINGLE_NUMBER_LENGHT];
string strMyString = " ";
string strTempString = " ";
int nCnt;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

infile.open( "myfile01.txt ", ios::in);
if (!infile) {
return 0;
}

while (!infile.eof()) {
infile.getline(cString, 127);
strMyString = cString;
nStringLenght = strMyString.length();
for (int i = 0;; i++) { // 这里判断 i < nStringLenght 没什么意义

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int nCommaPos = strMyString.find( ", ");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if (nCommaPos == -1) {

// 找不到，最后一个
nIntegerNumber[i] = atoi(strMyString.c_str());
nCnt = i + 1; // 计数
break;
}

memset(cTempChar, '\0 ', 10);
strTempString = strncpy(cTempChar, strMyString.c_str(), nCommaPos);
strMyString = strMyString.c_str() + nCommaPos + 1; // 主要是要把取出的去掉

nTempValue = atoi(cTempChar);
nIntegerNumber[i] = nTempValue;
}
}

infile.close();
QuickSort(nIntegerNumber, 0, nCnt - 1 );

//~~
// 和元素的个数有关
int i;
//~~

for (i = 0; i < nCnt; i++) {
printf( "%d ", nIntegerNumber[i]);
}

return 0;
}

------解决方案--------------------

# include <stdio.h>
# include <time.h>

# define MAXSIZE 2000

typedef struct{
int key[MAXSIZE];
int length;
}list;

long int compCount;
long int shiftCount;

{
int i;
char menu[6][15]={ "1 CREATE ", "2 IMPORT ", "3 SORT ", "4 SHOW RESULT ",
"5 SAVE RESULT ", "6 EXIT "};
clrscr();
printf( "SORT COMPARE SYSTEM\n ");
for (i=0;i <6;i++) printf( "%s\n ",menu[i]);
printf( "\n Please Select (1-6):\n ");

scanf( "%d ",m);
}

{
int i;
char menusort[5][15]={ "1 SHELL SORT ", "2 QUICK SORT ", "3 HEAP SORT ",
"4 MERGE SORT ", "5 ALL SORT "};

clrscr();
printf( "SORT\n ");
printf( "\n Please Select (1-5):\n ");

scanf( "%d ",m);

}

{
int i;
char menushow[4][20]={ "1 SHELL SORT RESULT ", "2 QUICK SORT RESULT ",
"3 HEAP SORT RESULT ", "4 MERGE SORT RESULT "};

clrscr();
printf( "SHOW SORT RESULT\n ");
printf( "\n Please Select (1-4):\n ");

scanf( "%d ",m);
}