本文整理匯總了C++中CreateQueue函數的典型用法代碼示例。如果您正苦於以下問題:C++ CreateQueue函數的具體用法?C++ CreateQueue怎麽用?C++ CreateQueue使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了CreateQueue函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: main
int main()
{
Queue TestQueue = CreateQueue(10);
cout << "Begin test of queue " << endl;
for (int i = 0, n = 1; i < 10; i++, n *= 2)
{
cout << i + 1 << "> Enqueue : " << n<<endl;
Enqueue(n, TestQueue);
}
PrintQueue(TestQueue);
cout << "Is Full ? " << IsFull(TestQueue)<<endl;
for (int i = 0; i < 5; i++)
{
cout << i + 1 << " >Dequeue :" << Front(TestQueue) << endl;
Dequeue(TestQueue);
}
PrintQueue(TestQueue);
cout << "Front and dequeue: " << FrontAndDequeue(TestQueue)<<endl;
cout << "Now add more data to test the cicular array..." << endl;
for (int i = 0; i < 5; i++)
{
cout << i + 1 << "> Enqueue : " << i << endl;
Enqueue(i, TestQueue);
}
PrintQueue(TestQueue);
cout << "Now make the queue empty...";
MakeEmpty(TestQueue);
cout << "Is Empty ? "<<IsEmpty(TestQueue)<<endl;
cout << "Now dipose the queue!" << endl;
DisposeQueue(TestQueue);
cout << "Test Succeed!" << endl << "Good bye!"<<endl;
getchar();
}
示例2: BFSTraversal
int BFSTraversal(GNode* graphRoot,int u,int v){
QNode* queue=CreateQueue(graphRoot->count);
EnQueue(queue,u);
int data;
ALNode* tmpNode;
while(!IsEmptyQueue(queue)){
data=DeQueue(queue);
if(visited[data]==0){
//printf("%d ",data);
tmpNode=graphRoot->GArray[data]->head;
while(tmpNode){
if(tmpNode->destination==v){
return 1;
}
if(visited[tmpNode->destination]==0){
EnQueue(queue,tmpNode->destination);
}
tmpNode=tmpNode->next;
}
visited[data]=1;
}
}
return 0;
}
示例3: main
int main()
{
FILE *ptr;
ptr=fopen("file.txt","r");
CheckFileForError(ptr);
CreateQueue();
char str[80];
int i, pnum, atime,btime;
while(fgets(str,80,ptr)!=NULL)
{
int *point;
point = FindNuminString(str,0);
pnum = *point;
point = FindNuminString(str,*(point+1));
atime = *point;
point = FindNuminString(str,*(point+1));
btime = *point;
EnQueue(pnum,atime,btime);
}
int time_quantum;
printf("\n Enter the time quantum: ");
scanf("%d",&time_quantum);
CalculateRR(time_quantum);
fclose(ptr);
DeleteQueue();
return 0;
}
示例4: findBottomLeftValue
int findBottomLeftValue(TreeNode* root) {
Trique*q=zCreateQueue(1000);;
Queue*level=CreateQueue(1000);
zEnqueue(q,root);
Enqueue(level,0);
int m=0;
while(q->NumElements){
TreeNode *r = zFront(q);
zDequeue(q);
int l = Front(level);
Dequeue(level);
if(r->left) {
zEnqueue(q,r->left);
Enqueue(level,l+1);
}
if(r->right){
zEnqueue(q,r->right);
Enqueue(level,l+1);
}
if(l > m){
m = l;
root = r;
}
}
return root->val;
}
示例5: Bfs
void Bfs(int graph[][maxVertices], int *size, int presentVertex,int *visited)
{
visited[presentVertex] = 1;
/* Iterate through all the vertices connected to the presentVertex and perform bfs on those
vertices if they are not visited before */
Queue *Q = CreateQueue(maxVertices);
Enqueue(Q,presentVertex);
while(Q->size)
{
presentVertex = Front(Q);
printf("Now visiting vertex %d\n",presentVertex);
Dequeue(Q);
int iter;
for(iter=0;iter<size[presentVertex];iter++)
{
if(!visited[graph[presentVertex][iter]])
{
visited[graph[presentVertex][iter]] = 1;
Enqueue(Q,graph[presentVertex][iter]);
}
}
}
return;
}
示例6: LevelOrderTraversal
void LevelOrderTraversal(struct TNode* root,int n){
if(!root){
return;
}
QNode* queue=CreateQueue(n);
EnQueue(queue,root);
struct TNode* tmpNode;
while(!IsEmptyQueue(queue)){
tmpNode=DeQueue(queue);
if(tmpNode){
printf("%d ",tmpNode->data);
}
if(tmpNode->left){
EnQueue(queue,tmpNode->left);
}
if(tmpNode->right){
EnQueue(queue,tmpNode->right);
}
}
}
示例7: bfs_iterative
void bfs_iterative(LGraph graph, Vertex start, void (*func)(nodeptr p))
{
int visited[graph->vertex_num];
Queue queue = CreateQueue(graph->vertex_num);
nodeptr curr;
curr = graph->G[start];
visited[curr->adjv] = 1;
enqueue(queue, curr);
while (!QIsEmpty(queue))
{
while (curr)
{
if (visited[curr->adjv] != 1)
{
enqueue(queue, curr);
visited[curr->adjv] = 1;
}
else
curr = curr->next;
}
nodeptr temp = dequeue(queue);
curr = graph->G[temp->adjv];
(*func)(curr);
}
}
示例8: CheckIfCompleteBinaryTree
int CheckIfCompleteBinaryTree(struct TNode* root,int n){
QNode* queue=CreateQueue(n);
struct TNode* tmpNode;
EnQueue(queue,root);
int result;
while(!IsEmptyQueue(queue)){
tmpNode=DeQueue(queue);
if(IsFullNode(tmpNode)){
EnQueue(queue,tmpNode->left);
EnQueue(queue,tmpNode->right);
}else if(tmpNode->right){
result=0;
break;
}else if(tmpNode->left){
continue;
}
else{
while(IsLeafNode(tmpNode) && !IsEmptyQueue(queue)){
tmpNode=DeQueue(queue);
}
if(IsEmptyQueue(queue)){
result=1;
break;
}else{
result=0;
break;
}
}
}
return result;
}
示例9: main
int main(int argc, char *argv[]){
int a,cevap;
struct Queue *q;
printf("Siradaki eleman sayisi:");
QueueSize(q);
if(isEmpty(q)==0){
printf("Kuyruk bos!");
}
if(isFull(q)==0){
printf("Kuyruk dolu!");
}
switch(cevap){
case 1: printf("1)bos kuyruk yaratmak icin:");
break;
case 2: printf("2)Kuyruga kisi eklemek icin");
break;
case 3: printf("3)Kuyruktan kisi silmek icin ");
break;
default: printf("Hata! 1 2 ya da 3 e basiniz.");
break;
}
if(cevap==1) CreateQueue(q);
if(cevap==2) Enqueue(q);
if(cevap==3) Dequeue(q,a);
}
示例10: ConditionConstructor
//Limit of the queue, and the id of this condition variable{NOT_FULL,NOT_EMPTY}
ConditionPtr ConditionConstructor(int limit, int ID){
ConditionPtr condition = (ConditionPtr) malloc(sizeof(ConditionStr));
condition->queue = (Queue)CreateQueue(limit);
condition->id = ID;
return condition;
}
示例11: Queue_is_Empty
void Queue_is_Empty()
{
Queue Q;
Q = CreateQueue();
assert(IsEmpty(Q) == true);
DisposeQueue(Q);
}
示例12: setup_usart
/* Initialize the USART6. */
void setup_usart(void) {
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable the GPIOC peripheral clock. */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
/* Make PC6, PC7 as alternative function of USART6. */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6);
/* Initialize PC6, PC7. */
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Enable the USART6 peripheral clock. */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);
/* Initialize USART6 with
* 115200 buad rate,
* 8 data bits,
* 1 stop bit,
* no parity check,
* none flow control.
*/
USART_InitStructure.USART_BaudRate = 115200;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART6, &USART_InitStructure);
/* Enable USART6. */
USART_Cmd(USART6, ENABLE);
/* Initial the USART TX streams. */
for(usart_stream_idx = MAX_USART_STREAM;
usart_stream_idx > 0;
usart_stream_idx--)
ClearStream(usart_stream + usart_stream_idx - 1);
/* Initial the RX Queue. */
rxQueue = &__rxQueue;
CreateQueue(rxQueue, __rxBuf, RX_QUEUELEN, sizeof(uint8_t));
if(rxQueue != NULL)
USART_Printf(USART2, "RX pipe created.\r\n");
else
USART_Printf(USART2, "RX pipe created failed.\r\n");
/* Disable RX pipe first. */
USART_DisableRxPipe(USART6);
/* Enable USART6 RX interrupt. */
USART_ITConfig(USART6, USART_IT_RXNE, ENABLE);
/* Enable USART6 in NVIC vector. */
NVIC_EnableIRQ(USART6_IRQn);
}
示例13: main
int main()
{
CreateQueue();
CreateMGraph();
ListComponents();
return 0;
}
示例14: main
//-----------------------------------------------
// Test a 4-entry queue
//-----------------------------------------------
int main()
{
int elem = 0;
queue *Q;
CreateQueue(Q, 4);
Dequeue(Q);
Enqueue(Q, ++elem);
Enqueue(Q, ++elem);
Enqueue(Q, ++elem);
Enqueue(Q, ++elem);
Dequeue(Q);
Enqueue(Q, ++elem);
Enqueue(Q, ++elem);
Dequeue(Q);
Enqueue(Q, ++elem);
Dequeue(Q);
Enqueue(Q, ++elem);
Dequeue(Q);
Dequeue(Q);
Dequeue(Q);
Dequeue(Q);
DestroyQueue(Q);
return 0;
}
示例15: TEST_F
TEST_F(TQueueTest, can_detect_when_queue_is_full)
{
CreateQueue(3);
SetUpFullQueue();
ASSERT_TRUE(queue->IsFull());
}