当前位置: 首页>>代码示例>>C++>>正文


C++ enQueue函数代码示例

本文整理汇总了C++中enQueue函数的典型用法代码示例。如果您正苦于以下问题:C++ enQueue函数的具体用法?C++ enQueue怎么用?C++ enQueue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了enQueue函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: bfs_traverse

void bfs_traverse(double road[][MAX_POINT])
{
	int visited[MAX_POINT];
	int i;
	for (i = 1; i < MAX_POINT; i++)
		visited[i] = 0;
	struct queueLK *hq;
	initQueue(hq);
	for (i = 1; i < MAX_POINT; i++) {
		if (!visited[i]) {
			visited[i] = 1;
			visit(road, i);
			enQueue(hq, i);
			while (!emptyQueue(hq)) {
				int u = outQueue(hq);
				int j;
				for (j = 1; j < MAX_POINT; j++) {
					if (road[u][j] > 0.0001 && !visited[j]) {
						visited[j] = 1;
						visit(road, j);
						enQueue(hq, j);
					}
				}
			}
		}
	}
	clearQueue(hq);
}
开发者ID:fangwen,项目名称:datas,代码行数:28,代码来源:graph.c

示例2: isPathBfs

int isPathBfs(Graph g, Vertex v, Vertex w)
{
	int isPath = FALSE;
	Queue q = newQueue(); // create a new queue
	Vertex curV = 0;
	int *visited = calloc(g->nV, sizeof(int)); // allocate + init to 0
	int i = 0;

	assert(visited != NULL);
	enQueue(q, v);
	visited[v] = TRUE;

	while ( !isEmptyQueue(q) ){ // still have vertices to traverse
		curV = deQueue(q); // get a vertex from the queue
		printf("Visiting: %d.\n", curV);
		visited[curV] = TRUE; // mark it as visited
		if (curV == w) { isPath = TRUE; } 
		for (i = 0; i < g->nV; i++){ // find vertices to add to queue
			if (g->edges[curV][i] && !visited[i]){ // found a vertex to add
				enQueue(q, i); // add it to queue
				visited[i] = TRUE; // mark it as visited
			}
		}
	}	
	free(visited);
	deleteQueue(q);
	return isPath;
}
开发者ID:matthewT53,项目名称:Data-structures-and-algorithms,代码行数:28,代码来源:graph.c

示例3: checkStackPairwiseOrder

int checkStackPairwiseOrder(struct sNode *top) {
    struct Queue *q = createQueue();
    struct sNode *s = top;
    
    int pairwiseOrdered = 1;

    while (!isEmpty(s))
        enQueue(q, pop(&s));

    while (!queueIsEmpty(q))
        push(&s, deQueue(q)->key);

    while (!isEmpty(s)) {
        int n = pop(&s);
        enQueue(q, n);
        if (!isEmpty(s)) {
            int m  = pop(&s);
            enQueue(q, m);
            if(abs(n - m) != 1) {
                pairwiseOrdered = 0;
            }    
        }
    }    

    while (!queueIsEmpty(q))
        push(&s, deQueue(q)->key);
    return pairwiseOrdered;
}        
开发者ID:dataAlgorithms,项目名称:dataStructure,代码行数:28,代码来源:checkStackPairwiseOrder.c

示例4: breadthFirst

int breadthFirst(struct node * resgraph[], int from , int to, int nV, int parent[])
{
	int i;
	int visitList[nV];
	struct Queue * pop;
	struct node * var;
	for(i = 0;i < nV; i++)
	{
		visitList[i] = 0;
	}
	visitList[from] = 1;
	parent[from] = -1;
	enQueue(from);
	
	while(head != NULL)
	{
		pop = deQueue();
		var = resgraph[pop->nodes];
		while(var != NULL)
		{
			if(visitList[var->toNode] == 0 && var->weight > 0)
			{
				enQueue(var->toNode);
				visitList[var->toNode] = 1;
				parent[var->toNode] = pop->nodes;
			}
			var = var->next;
		}
	}
	
	if(visitList[to] == 1)
		return 1;
	return 0;
}
开发者ID:rajareddy1863,项目名称:C-Codes,代码行数:34,代码来源:networkFlow.c

示例5: main

int main(void){
    
    Queue_t *q;
    Stack_t *stack1 = (Stack_t*)malloc(sizeof(Stack_t));
    Stack_t *stack2 = (Stack_t*)malloc(sizeof(Stack_t));
    
    q->basic = stack1;
    q->forDequeue = stack2;
    
    puts("//enqueue");
    enQueue(q, 1);
    enQueue(q, 2);
    enQueue(q, 3);
    
    printQueue(q);
    
    puts("//deQueue");
    deQueue(q);
    deQueue(q);
    printQueue(q);
    
    deQueue(q);
    printQueue(q);
    
    deQueue(q);
    
    
    
    
    return 0;
    
}
开发者ID:Kyoo32,项目名称:NEXT2015-1,代码行数:32,代码来源:queue_by_two_stacks.c

示例6: isBipartite

bool isBipartite(int G[][V], int src)
{
    int colorMatrix[V], color, temp, u;

    initColorMatrix(colorMatrix, V);

    struct Queue* queue = createQueue(V);

    color = 1;
    colorMatrix[src] = color;
    enQueue(queue, src);

    while (!isEmpty(queue))
    {
        temp = deQueue(queue);
        // assign alternate color to its neighbor
        color = 1 - colorMatrix[temp];

    	for (u = 0; u < V; ++u)
        {
        	// an edge exists and destination not colored
        	if (G[temp][u] && colorMatrix[u] == -1)
	        {
		        colorMatrix[u] = color;
                enQueue(queue, u);
	        }

            else if (G[temp][u] && colorMatrix[u] == colorMatrix[temp])
                return false;
        }
    }

    return true;
}
开发者ID:hermesdragon,项目名称:CODING,代码行数:34,代码来源:bp2.c

示例7: bfs

void bfs(struct Graph *graph, int s)
{

    int visited[graph->v];
    for (int i = 0; i < graph->v; i++)
        visited[i] = G_FALSE;
    visited[s] = G_TRUE;
    
    struct Queue *queue = newQueue(10);
    enQueue(queue, s);
    
    fprintf(stderr, "BFS\n");
    while (!isEmpty(queue)) {
        int temp = deQueue(queue);
        fprintf(stderr, "%d\n", temp);
        struct adjListNode *cur = graph->array[temp].head;
        while (cur){
            if (!visited[cur->dest]) {
                visited[cur->dest] = G_TRUE;
                enQueue(queue,cur->dest);
            }
            cur = cur->next;
        }
    }
    return;
}
开发者ID:fun4xnm,项目名称:CLRS,代码行数:26,代码来源:graph.c

示例8: main

int main(void){

	printf("FIFO: First In First Out\n");

	printf("Queue is %s\n", (isEmpty()? "Empty": "Not Empty"));
	printf("Queue Size = %d\n", queueSize());

	enQueue(1);
	enQueue(2);
	enQueue(13);
	enQueue(6);

	printQueue();
	printf("Queue Size = %d\n", queueSize());


	printf("1st DeQueue = 1 || deQueue Result = %d\n", deQueue());
	printf("2nd DeQueue = 2 || deQueue Result = %d\n", deQueue());
	printf("Queue Size = %d\n", queueSize());

	printQueue();

	printf("3rd DeQueue = 13 || deQueue Result = %d\n", deQueue());
	printf("4th DeQueue = 6  || deQueue Result = %d\n", deQueue());

	printf("Add 6 to the queue\n");
	enQueue(6);
	printQueue();

	printf("Queue Size = %d\n", queueSize());
	printf("Queue is %s\n", (isEmpty()? "Empty": "Not Empty"));


	return 0;
}
开发者ID:AbdulmalikGadeer,项目名称:C-Language,代码行数:35,代码来源:Queue.c

示例9: start

void
start(void)
{
	int i;
	//exercise 4A
	//sys_priority (PRIORITY);
	//exercise 7
	queue_t frontground = initQueue();
	queue_t background = initQueue();
	sys_multilevelq (QUEUE);
	sys_yield();
	for (i = 0; i < RUNCOUNT; i++) {
		if (current->queue_name == q_foreground)
		{
			enQueue (frontground, pid_t current->p_pid);
		}
		else if (current->queue_name == q_background)
		{
			enQueue (background, pid_t current->p_pid);
		}
		else
		{
			console_printf(cursorpos, 0x100, "error on enqueue");
		}
		// Write characters to the console, yielding after each one.
		*cursorpos++ = PRINTCHAR;
		sys_yield();
	}

	// Yield forever.
	//while (1)
		//sys_yield();
	sys_exit(0);
}
开发者ID:summerxuan,项目名称:cs111,代码行数:34,代码来源:schedos-1.c

示例10: configure_AccelRange

void configure_AccelRange(accelRange range){
	mpu_regs->accel_cfg &= ~BITS_FSR;
	mpu_regs->accel_cfg |= range;
	enQueue(mpuTxQueue, reg.accel_cfg);				// enqueue the register number
	enQueue(mpuTxQueue, mpu_regs->accel_cfg);	// enqueue the new value 
	mpu_writeRegister(1, reg.accel_cfg, false); // send to i2c interface
	
}
开发者ID:qosha1,项目名称:CS53-Code,代码行数:8,代码来源:mpu_control.c

示例11: test_inserting_elements_equal_to_size_of_queue

void test_inserting_elements_equal_to_size_of_queue(){
	CircularQueue* cQueue = create(sizeof(int),2);
	int element1 = 10;
	int element2 = 20;
	int res = enQueue(cQueue,&element1);
	res = enQueue(cQueue,&element2);
	ASSERT(1 == res);
};
开发者ID:pallavig,项目名称:dsa,代码行数:8,代码来源:circularQueueTest.c

示例12: test_inserts_the_element_first_having_higher_priority_float

void test_inserts_the_element_first_having_higher_priority_float(){
	void* pQueue = createPQueue();
	float data1 = 10.0f , data2 = 20.0f;
	ASSERT(1 == enQueue(pQueue, &data2, 2));
	ASSERT(1 == enQueue(pQueue, &data1, 1));
	ASSERT(1 == deQueue(pQueue));
	ASSERT(1 == deQueue(pQueue));
	ASSERT(0 == deQueue(pQueue));
};
开发者ID:shwetado,项目名称:DSA,代码行数:9,代码来源:pQueueTest.c

示例13: test_to_enqueue_an_int_element_when_queue_is_full

void test_to_enqueue_an_int_element_when_queue_is_full(){
	int element = 4;
	Queue* queue = create(sizeof(int), 2);
	enQueue(queue, &element);
	enQueue(queue, &element);
	ASSERT(0==enQueue(queue, &element));
	free(queue->base);
	free(queue);	
}
开发者ID:jainsahab,项目名称:Queue,代码行数:9,代码来源:queueLibTest.c

示例14: test_to_check_the_behaviour_on_full_capacity

void test_to_check_the_behaviour_on_full_capacity(){
	int element = 4;
	queue = create(sizeof(int), 4);
	ASSERT(enQueue(queue, &element));
	ASSERT(enQueue(queue, &element));
	ASSERT(enQueue(queue, &element));
	ASSERT(enQueue(queue, &element));
	ASSERT(false==enQueue(queue, &element));
}
开发者ID:jainsahab,项目名称:circularQueue,代码行数:9,代码来源:queueLibTest.c

示例15: test_to_enter_element_in_queue_when_it_is_full_11

void test_to_enter_element_in_queue_when_it_is_full_11(){
	Queue* actual = createQueue(2,sizeof(int));
	int value[3] = {1,2,3};
	int* data = (int*)actual->elements;
	enQueue(actual,&value[0]);
	enQueue(actual,&value[1]);
	ASSERT(0==enQueue(actual,&value[2]));
	free(actual);
}
开发者ID:rvgorlov,项目名称:DSA,代码行数:9,代码来源:queueTest.c


注:本文中的enQueue函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。