void CMyDlg::insertsort()
{
//对输入的字符进行排序 int m,n;
CString temp; for (m=0; m<max; m++)
{
temp=wordlist[m];
n=m-1;
while(temp<wordlist[n])
{
wordlist[n+1]=wordlist[n];
n--;
};
wordlist[n+1]=temp;
}
}
我在一个折半查找程序先加入一个插入排序的程序,先对输入的字符串数组进行排序,可是运行时就出错,上面的wordlist[]就是我的输入的字符串数组,大家看看为什么啊?
{
//对输入的字符进行排序 int m,n;
CString temp; for (m=0; m<max; m++)
{
temp=wordlist[m];
n=m-1;
while(temp<wordlist[n])
{
wordlist[n+1]=wordlist[n];
n--;
};
wordlist[n+1]=temp;
}
}
我在一个折半查找程序先加入一个插入排序的程序,先对输入的字符串数组进行排序,可是运行时就出错,上面的wordlist[]就是我的输入的字符串数组,大家看看为什么啊?
{
temp=wordlist[m];
n=m-1; //!!!当m为0时n是-1,数组溢出!
while(temp<wordlist[n])
{
wordlist[n+1]=wordlist[n];
n--;
};
wordlist[n+1]=temp;
}