Thinks your good answer very much.
crazy66
Posts
-
"Advanced programming in the UNIX environment" Book Code -
"Advanced programming in the UNIX environment" Book Code#include "apue.h" Did you have the head file? Or Did you have the book source code? It is The 2nd Edition better , but the 1st edition maybe suitably. Thx.
-
Please recommend me a com book.I have a good grasp of the c++ language and mfc. Please recommend me a com book. Thank you very much. ;)
-
How to prevent Quicksort stack overflow?My aim is to learn the data structure, in the QuickSort algorithm . 0.6s to complete the order that is 1 million random numbers. 1. However, if the rand number such as rand ()% 2, such a random number will be occur stack overflow , the problem is very difficult for me , in order to keeping the rapid nature of QuickSort, may I ask how to solve the stack overflow problem. 2. But luckily no stack overflow if the situation is still rand ()% 2, such a random number calculate the time to reach 17s. Thank you very much. Attached on the source code:
void SwitchNum(int& n1,int& n2)
{
int nTemp=n1;
n1=n2;
n2=nTemp;
}void QuickSort(int *pnArray,int nSize)
{
if (nSize>1)
{
int nNum=nSize/2,i=0,j=nSize-1;
while (i!=j)
{
for (;j>nNum;j--)
{
if (pnArray[nNum]>pnArray[j])
{
SwitchNum(pnArray[nNum],pnArray[j]);
nNum=j;
break;
}
}
for (;i <nNum;i++)
{
if (pnArray[nNum] <pnArray[i])
{
SwitchNum(pnArray[nNum],pnArray[i]);
nNum=i;
break;
}
}
}
QuickSort(pnArray,nNum);
QuickSort(pnArray+nNum+1,nSize-nNum-1);
}
}