int main() { LinkQueue Q; if(InitQueue(&Q)) { QElemType e; printf("initialize successful"); if(IsEmpty(Q)) { printf("queue is IsEmpty\n"); } for (int i=0;i<10;i++) { EnQueue(&Q,i); } GetHead(Q,&e); printf("The head element is %d\n",e ); printf("The length of the queue is %d\n",GetLength(Q)); DeQueue(&Q,&e); printf("delete element is %d\n",e); TraverseQueue(Q,*visit); if (DestroyQueue(&Q)) { printf("DestroyQueue successful\n"); } } return 0; }
//从左子节点开始遍历树 static void InOrder(const Node * root,void (* pfun)(Item item)) { if(root != NULL) { InOrder(root->left,pfun); TraverseQueue(root->queue,pfun); InOrder(root->right,pfun); } }
int main() { Queue q; int nData = 0; int nLength = 0; BOOL bEmpty = FALSE; InitQueue(&q); EnQueue(&q, 12); EnQueue(&q, 3); EnQueue(&q, 8); EnQueue(&q, 34); EnQueue(&q, 6); EnQueue(&q, 9); EnQueue(&q, 56); EnQueue(&q, 78); EnQueue(&q, 4); EnQueue(&q, 90); printf("入队后的队列:"); TraverseQueue(&q, OutputQueue); nLength = GetQueueLength(&q); printf("队列长度:%d\n", nLength); bEmpty = IsQueueEmpty(&q); printf("队列为%s\n", bEmpty ? "空" : "非空"); DeQueue(&q, &nData); printf("出队数据:%d\n", nData); printf("出队后的队列:"); TraverseQueue(&q, OutputQueue); DeQueue(&q, &nData); printf("出队数据:%d\n", nData); printf("出队后的队列:"); TraverseQueue(&q, OutputQueue); DestroyQueue(&q); return 0; }
/* * === FUNCTION ====================================================================== * Name: main * Description: * ===================================================================================== */ int main ( int argc, char *argv[] ) { LinkQueue Q; if(InitQueue(&Q)) { QElemtype e; int i; printf("Init Success\n"); if(IsEmpty(Q)) { printf("Queue is Empty\n"); } for(i = 0; i < 10; i++) { EnQueue(&Q, i); } GetHead(Q, &e); printf("The first element is %d\n", e); printf("Length is %d\n", GetLength(Q)); DeQueue(&Q,&e); printf("Delete element is %d \n", e); TraverseQueue(Q, *visit); if(DestroyQueue(&Q)) { printf("\n DestroyQueue Success\n"); } } return EXIT_SUCCESS; } /* ---------- end of function main ---------- */
//判断目标元素是否存在于树中 BOOL InTree(const Item * pi,const Tree * ptree,void (* pfun)(Item item)) { Pair look; return ((look = SeekItem(pi,ptree)).child == NULL)?FALSE:TraverseQueue(look.child->queue,pfun); }