Ejemplo n.º 1
0
/*
 * Realizes the queue ADT with an Array and then a LinkedList
 */
int main(void) {
    Queue queue;

    printf("Array Queue Tests\n");
    newArrayQueue(&queue);
    testQueue(&queue);
    deleteArrayQueue(&queue);

    printf("\n");
    printf("Linked Queue Tests\n");
    newLinkedQueue(&queue);
    testQueue(&queue);
    deleteLinkedQueue(&queue);
    return 0;
}
Ejemplo n.º 2
0
void levelOrderTraversalBinTree(BinTree *pBinTree)
{
	LinkedQueue* pQueue = NULL;
	QueueNode* pQueueNode = NULL;
	BinTree* pSubTree = NULL;
	BinTreeNode *pRootNode = NULL, *pLeftChildNode = NULL, *pRightChildNode = NULL;

	if (pBinTree == NULL) {
		return;
	}
	pRootNode = getRootNodeBT(pBinTree);
	if (pRootNode == NULL){
		return;
	}
	pQueue = createLinkedQueue();
	if (pQueue == NULL) {
		return;
	}
	enqueueLQBinTreeNode(pQueue, pRootNode);
	while(1) {
		if (isLinkedQueueEmpty(pQueue) == TRUE) {
			return;
		}
		else {
			pQueueNode = dequeueLQ(pQueue);
			if (pQueueNode != NULL) {
				pRootNode = pQueueNode->data;

				if (pRootNode != NULL) {
					printf("%c ", pRootNode->data);
				}
				pLeftChildNode = getLeftChildNodeBT(pRootNode);
				pRightChildNode = getRightChildNodeBT(pRootNode);
				if (pLeftChildNode != NULL) {
					enqueueLQBinTreeNode(pQueue, pLeftChildNode);
				}
				if (pRightChildNode != NULL) {
					enqueueLQBinTreeNode(pQueue, pRightChildNode);
				}

				free( pQueueNode );
			}
		}
	}
	deleteLinkedQueue(pQueue);
}
Ejemplo n.º 3
0
void deleteDefBlockingQueue(BlockingQueue *queue)
{
	LinkedQueue *linkedQueue = container_of(queue->queue, LinkedQueue, iqueue);
	deleteLinkedQueue(linkedQueue);
	deleteBlockingQueue(queue);
}