Beispiel #1
0
void *PullThreadQueue(ThreadQueue *q, uint32_t timeout)
{
	int err = SemaphoreWaitTimeout(q->sem, timeout);
	if (err == 0) {
		void *p = QueueFront(q->queue);
		QueuePopFront(q->queue);
		return p;
	}
	if (err != -ETIMEDOUT)
		error("failed: %d.", err);
	return NULL;
}
Beispiel #2
0
/** Removes and Returns the first element of the Queue.
	This function returns NULL if the Queue is empty.

\param Q The Queue to perform this function on
\return Returns the front element in the Queue
*/
void* QueuePop(Queue* Q) 
{
	void* X = QueueFront(Q);
	if(!QueueIsEmpty(Q)) 
	{
		Q->size--;
		Q->front++;
		if(Q->front >= Q->capacity)
			Q->front = 0;
	}
	else
		//xil_printf("Queue is empty!\r\n");

	return X;
}
Beispiel #3
0
// 二叉树的镜像非递归 
void MirrorBinTreeNor(pBTNode pRoot)
{
	LQueue q;
	InitQueue(&q);
	PushQueue(&q, pRoot);
	while (!QueueEmpyt(&q)) {
		pBTNode pCur = QueueFront(&q);
		PopQueue(&q);
		if (pCur->_pLeft)
			PushQueue(&q, pCur->_pLeft);
		if (pCur->_pRight)
			PushQueue(&q, pCur->_pRight);
		swap(&pCur->_pLeft, &pCur->_pRight);
	}
}
Beispiel #4
0
// 层序遍历 
void LevelOrder(pBTNode pRoot)
{
	LQueue q;
	InitQueue(&q);
	PushQueue(&q, pRoot);
	while (!QueueEmpyt(&q)) {
		pBTNode pCur = QueueFront(&q);
		PopQueue(&q);
		printf("%c ", pCur->_data);
		if(pCur->_pLeft)
			PushQueue(&q, pCur->_pLeft);
		if (pCur->_pRight)
			PushQueue(&q, pCur->_pRight);
	}
}
Beispiel #5
0
/** Code to test this Queue implementation
This code is only included for example purposes and to ensure that 
this implementation works in all situations

This code at present is not exhaustive.

STEPS:
- Test 1
  -# Push some integers onto the Queue inplace of pointers.
  -# Pop all of the elements off the queue to make sure that they match
- Test2 
  -# TODO 

\todo Write a more exhaustive test 

*/
int QueueTest()
{
	Queue queue;
	void* ary[10];

	QueueInit( &queue, ary, 10 );

	// Test 1
	{
		{
			int i;
			for( i = 0 ; i < 10 ; i++ )
				QueuePush( &queue, (void*) i ); 
		}

		if(QueueIsFull(&queue) != TRUE)
			return 1;

		{
			int i;
			for( i = 0 ; i < 10 ; i++ )
			{
				int val = (int) QueuePop( &queue );
				if(val != i)
					return 2;
			}		
		}
		
		if(QueueIsEmpty(&queue) != TRUE)
			return 3;

		if(QueueIsFull(&queue) != FALSE)
			return 4;
	}


	// Test 2
	{
		QueuePush( &queue, (void*) 1234); 
		if((int)QueueFront(&queue) != 1234)
			return 5;
	}


	return 0;
}
Beispiel #6
0
/***********************7。图的广度周游**********************/
void BFS(GRAPH g, int v, int mark[])
//从v出发广度优先周游图g中能访问的各个顶点
{
	int v1, v2;
	SEQQUEUE q;
	QueueInit(&q);
	QueueIn(&q, v);
	mark[v] = 1;
	printf("%c   ", g.vexs[v]);
	while (QueueIsEmpty(q) == 0)
	{
		QueueFront(q, &v1);
		QueueOut(&q);
		for (v2 = 0; v2 < g.num; v2++)
		{
			if (g.arcs[v1][v2] != 0 && mark[v2] == 0)
			{
				QueueIn(&q, v2);
				mark[v2] = 1;
				printf("%c   ", g.vexs[v2]);
			}
		}
	}
}