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(); }
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; }
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; }
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; }
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; }
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); } } }
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); } }
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; }
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); }
//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; }
void Queue_is_Empty() { Queue Q; Q = CreateQueue(); assert(IsEmpty(Q) == true); DisposeQueue(Q); }
/* 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); }
int main() { CreateQueue(); CreateMGraph(); ListComponents(); return 0; }
//----------------------------------------------- // 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; }
TEST_F(TQueueTest, can_detect_when_queue_is_full) { CreateQueue(3); SetUpFullQueue(); ASSERT_TRUE(queue->IsFull()); }
void printReverseLevelOrder(tree_node *root){ Stack *st = CreateStack(); Queue *q = CreateQueue(); enqueue(q, root); enqueue(q, NULL); while(!isEmpty(q)){ tree_node *tmp = dequeue(q); if(tmp == NULL){ //level changed if(!isEmpty(q)){ enqueue(q, NULL); } } else { push(st, tmp); if(tmp->left != NULL) enqueue(q, tmp->left); if(tmp->right != NULL) enqueue(q, tmp->right); } } while(!isEmptyStack(st)){ printf("%d \t", pop(st)->data); } printf("\n"); free(q); free(st); }
int main() { int msqid; key_t key; struct mymsgbuf mybufin; key = GenerateKey(); msqid = CreateQueue(); semid = CreateSemaphore(); while (1) { if ((msgrcv(msqid, (struct msgbuf *)&mybufin, sizeof(struct dish),2 , 0)) < 0) { printf("Can\'t receive message from queue\n"); exit(-1); } printf("Dish is wiping: size %d, amount of water %d\n", mybufin.cleanDish.size, mybufin.cleanDish.amountOfWater ); sleep( mybufin.cleanDish.size + mybufin.cleanDish.amountOfWater ); printf("Dish was wiped\n"); ChangeSemaphore(semid, mybufin.cleanDish.size); } return 0; }
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); } CalculatePSJF(); fclose(ptr); DeleteQueue(); return 0; }
int main(){ struct ArrayQueue *Q = CreateQueue(); //printf("%d \n",Dequeue(Q)); Enqueue(Q,1); Enqueue(Q,2); Enqueue(Q,3); Enqueue(Q,4); printf("%d \n",Dequeue(Q)); printf("%d \n",Dequeue(Q)); Enqueue(Q,5); Enqueue(Q,6); printf("%d \n",Dequeue(Q)); printf("%d \n",Dequeue(Q)); Enqueue(Q,7); Enqueue(Q,8); Enqueue(Q,9); Enqueue(Q,10); Enqueue(Q,20); Enqueue(Q,30); Enqueue(Q,40); for(int i=0;i<10;i++){ printf("A %d \n",Q->array[i]); } }
void InitPathFinder(PathFinder* pathFinder, Map* map, bool diagonal) { pathFinder->map = map; pathFinder->openList = CreateQueue(nodeMinCompare, map->width * map->height); // Clear our internal map pathFinder->nodeMap = malloc(sizeof(Node*) * map->width); for (int i = 0; i < map->width; ++i) { pathFinder->nodeMap[i] = malloc(sizeof(Node) * map->height); memset(pathFinder->nodeMap[i], 0, sizeof(Node) * map->height); } for (int i = 0; i < map->width; i++) { for (int e = 0; e < map->height; e++) { pathFinder->nodeMap[i][e].x = i; pathFinder->nodeMap[i][e].y = e; pathFinder->nodeMap[i][e].open = NoList; } } //pathFinder->path = malloc(sizeof(PathNode) * map->height * map->width); //pathFinder->pathSize = 0; pathFinder->path = NULL; pathFinder->allowDiagonal = diagonal; }
int main(void) { /* int *temp = (int*)malloc(4*sizeof(int)); int i =1; printf("%d %d",temp,temp+i);*/ int i=0; int data; Queue testqueue = CreateQueue(5); for(i=0;i<100;i++) { Enqueue(i,testqueue); } for(i=0;i<50;i++) { data = Dequeue(testqueue); printf("%d ",data); } for(i=100;i<200;i++) { Enqueue(i,testqueue); } for(i=0;i<150;i++) { data = Dequeue(testqueue); printf("%d ",data); } puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ return EXIT_SUCCESS; }
int main( ) { Queue Q; int i; Q = CreateQueue( 12 ); FAIL_ON_NULL(Q->data) i=0; for( i = 0; i < 10; i++ ) Enqueue( i, Q ); while( !IsEmpty( Q ) ) { printf( "%d\n", Front( Q ) ); Dequeue( Q ); } for( i = 0; i < 20; i++ ) Enqueue( i, Q ); while( !IsEmpty( Q ) ) { printf( "%d\n", Front( Q ) ); Dequeue( Q ); } DisposeQueue( Q ); return 0; }
int main(){ int value, i; int n =10; QueType* q1 = NULL; QueType* q2 = NULL; //QueType* q3 = NULL; QueType* q4 = NULL; QueType* queue; //queue = CreateQueue(); int count = 0; queue = CreateQueue(); printf ( "\n Enter elements in the queue : ") ; scanf("%d\n",&value); // for(i=0;i<=10;i++){ while(value != -9999){ Enqueue(queue,value); scanf("%d\n", &value); value++;} if(i=1;i<10;i++){ Enqueue(q1,value); printf("%d element in the q1", value); scanf("%d\n", &value); } else
TEST_F(TQueueTest, can_detect_when_queue_is_not_full) { CreateQueue(3); queue->Push(1, "a"); queue->Push(2, "b"); ASSERT_FALSE(queue->IsFull()); }
TEST_F(TQueueTest, can_push_element) { CreateQueue(); queue->Push(1, "a"); ASSERT_EQ(1, queue->GetSize()); }
TEST_F(TQueueTest, throws_when_pop_from_empty_queue) { double key; void* value; CreateQueue(3); ASSERT_ANY_THROW(queue->Pop(&key, &value)); }
/** * Creates the queue of AutoCommand instances */ void AutonomousController::StartAutonomous() { printf("Starting auto \n"); CreateQueue(); currentCommand = firstCommand; if (currentCommand != NULL) { currentCommand->Init(); } }
int main() { struct Queue *q = CreateQueue(); Insert(q,1,1); Insert(q,2,6); Insert(q,6,2); printf("%d\n",Delete(q)->element); return 0; }
TEST_F(TQueueTest, can_clear_queue) { CreateQueue(3); SetUpFullQueue(); queue->Clear(); ASSERT_TRUE(queue->IsEmpty()); }
void *HouseThread(void *arg) { UpdateObjectType *msg; int x; int timeCounter = 0; int childCounter = 0; signal(SIGUSR1, FastExit); srand48(time(NULL)); for(;;) { pthread_mutex_lock(&updateMutex); if(updateQueue) { msg = Dequeue(&updateQueue); pthread_mutex_unlock(&updateMutex); pthread_mutex_lock(&clientMutex); for(x = 0; x < MAX_CLIENTS; x++) { if(client[x].ns > -1) { write(client[x].ns, msg, sizeof(UpdateObjectType)); } } pthread_mutex_unlock(&clientMutex); free(msg); pthread_mutex_lock(&updateMutex); } pthread_mutex_unlock(&updateMutex); usleep(SLEEP_TIME); ++timeCounter; if(timeCounter == TIME_MODULUS) { timeCounter = 0; pthread_mutex_lock(&houseMutex); houseObject.level[1] += 5; if((houseObject.level[1] & 0xFF) >= 60) { houseObject.level[1] &= ~0xFF; houseObject.level[1] = (houseObject.level[1] + 0x100) % (24 << 8); } pthread_mutex_unlock(&houseMutex); msg = GetHouseUpdate(); pthread_mutex_lock(&updateMutex); if(!updateQueue) { CreateQueue(&updateQueue); } Enqueue(&updateQueue, msg); pthread_mutex_unlock(&updateMutex); } childCounter = (childCounter + 1) % CHILD_MODULUS; if(!childCounter) { MoveChild(); } } return NULL; }