l***b 发帖数: 125 | 1 随手写的,输出解的个数和wiki上一样,估计是对的吧,没仔细测
int g_nTotalSolutionNum = 0;
void PrintSolution(int *pPos, int nQueue)
{
if (pPos == NULL)
{
return;
}
for ( int i = 0; i < nQueue; ++i )
{
cout << pPos[i] << ", ";
}
cout << endl;
++g_nTotalSolutionNum;
}
void NQueue(int nQueue)
{
if ( nQueue == 0 )
{
return;
}
int *pPos = new int[nQueue];
int nCurrCol = 0;
pPos[0] = 0;
for(;;)
{
if ( pPos[nCurrCol] == nQueue )
... 阅读全帖 |
|
S**Y 发帖数: 136 | 2 Given a constant number of priorities implement a priority queue with O(1) e
nqueue and dequeue implementations.
I can not think of a way doing this...O(1) enque and deque..
even with a constant number of prioritties..
Any ideas? |
|
d****n 发帖数: 233 | 3 Mark.
The following part at the end seems not needed:
if ( pPos[nCurrCol] == nQueue - 1 )
{
--nCurrCol;
++pPos[nCurrCol];
continue;
}
else |
|