本文整理汇总了C++中create_queue函数的典型用法代码示例。如果您正苦于以下问题:C++ create_queue函数的具体用法?C++ create_queue怎么用?C++ create_queue使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了create_queue函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: test_AppendQueues
void
test_AppendQueues(void) {
queue* q1 = create_queue();
queue* q2 = create_queue();
queue* q3 = create_queue();
queue* q4 = create_queue();
queue* q5 = create_queue();
// append empty queue to empty queue
append_queue(q1, q2); // destroys q2
element *e1_ptr, *e2_ptr, *e3_ptr, *e4_ptr, *e5_ptr, *e6_ptr;
e1_ptr = (element*)debug_get_node(sizeof(element));
e2_ptr = (element*)debug_get_node(sizeof(element));
e3_ptr = (element*)debug_get_node(sizeof(element));
e4_ptr = (element*)debug_get_node(sizeof(element));
e5_ptr = (element*)debug_get_node(sizeof(element));
e6_ptr = (element*)debug_get_node(sizeof(element));
enqueue(q1, e1_ptr);
enqueue(q1, e2_ptr);
enqueue(q1, e3_ptr);
// append empty queue to non empty queue
append_queue(q1, q3); // destroys q3
TEST_ASSERT_EQUAL(3, get_no_of_elements(q1));
// append non empty queue to empty queue
append_queue(q4, q1); // destroys q1
TEST_ASSERT_EQUAL(3, get_no_of_elements(q4));
enqueue(q5, e4_ptr);
enqueue(q5, e5_ptr);
// append non empty queue to non empty queue
append_queue(q4, q5); // destroys q5
TEST_ASSERT_EQUAL(5, get_no_of_elements(q4));
dequeue(q4);
dequeue(q4);
dequeue(q4);
dequeue(q4);
dequeue(q4);
free_node(e1_ptr);
free_node(e2_ptr);
free_node(e3_ptr);
free_node(e4_ptr);
free_node(e5_ptr);
free_node(e6_ptr);
TEST_ASSERT_EQUAL(0, get_no_of_elements(q4));
// destroy_queue(q1); // destroyed already
// destroy_queue(q2); // destroyed already
// destroy_queue(q3); // destroyed already
destroy_queue(q4);
// destroy_queue(q5); // destroyed already
}
开发者ID:qicny,项目名称:freebsd,代码行数:60,代码来源:ntp_prio_q.c
示例2: init_http_client
bool
init_http_client() {
debug( "Initializaing HTTP client." );
assert( http_client_thread == NULL );
assert( http_client_efd == -1 );
assert( main_efd == -1 );
assert( transactions == NULL );
http_client_efd = create_event_fd();
assert( http_client_efd >= 0 );
http_client_notify_count = 0;
set_fd_handler( http_client_efd, NULL, NULL, notify_http_client_actually, &http_client_notify_count );
set_writable( http_client_efd, false );
main_efd = create_event_fd();
assert( main_efd >= 0 );
set_fd_handler( main_efd, retrieve_http_transactions_from_http_client, NULL, NULL, NULL );
set_readable( main_efd, true );
assert( main_to_http_client_queue == NULL );
assert( http_client_to_main_queue == NULL );
main_to_http_client_queue = create_queue();
assert( main_to_http_client_queue != NULL );
http_client_to_main_queue = create_queue();
assert( http_client_to_main_queue != NULL );
create_http_transaction_db();
debug( "Initialization completed." );
return true;
}
开发者ID:deadcafe,项目名称:trash,代码行数:34,代码来源:http_client.c
示例3: main
int main(int argc, char** argv){
static pthread_t thread_serial_id;
static pthread_t thread_flush_serial;
static pthread_t thread_commands;
Queue queue_input;
Queue queue_output;
create_queue(&queue_input);
create_queue(&queue_output);
int fd_;
connect_pty (&fd_);
data_t data = {
.fd = &fd_,
.input = queue_input,
.output = queue_output,
.mutex = PTHREAD_MUTEX_INITIALIZER,
};
int ret = pthread_create(&thread_serial_id, NULL, serial_simulation,
&data);
int ret2 = pthread_create(&thread_flush_serial, NULL, flush_serial,
&data);
int ret3 = pthread_create(&thread_commands, NULL, manage_commands,
&data);
pthread_join (thread_commands, NULL);
pthread_join (thread_serial_id, NULL);
pthread_join (thread_flush_serial, NULL);
return EXIT_SUCCESS;
}
开发者ID:evolutek,项目名称:motorboard_emulator,代码行数:35,代码来源:main.c
示例4: search_for_string_openmp
//OpenMP: Given a search string, the function performs a multi-threaded search of the file system starting from the specified path name.
void search_for_string_openmp(char **argv)
{
//What's going on, eh?
printf("OPENMP Execution Started.\n");
// 1 2 3
//<search string> <path> <# of threads>"
//Collect the command line args
char * to_find = argv[1];
char * start_path = argv[2];
unsigned int num_threads = atoi(argv[3]);
unsigned int num_found = 0;
//If there was some way to know where files were located on disk
//To further optimize disk access patterns... that would be neat.
//Ok two queues, one for directories to be searched through
//The other is for filenames themselves
queue_t * dir_queue = create_queue();
queue_t * file_queue = create_queue();
//We don't want queues being locked
//unlocked very often so each thread will pull off a certain number
//of items at a time to look at
unsigned int num_files_per_queue_access = 10;
unsigned int num_dirs_per_queue_access = 1;
//Need to build up a buffer of files in the list before starting
unsigned int file_queue_min_size = 1000;
//So threads will first look to the dir queue to keep finding files
//If no dirs exist then they will look in the file queue for files
//to search through
//Prime the dir queue with the starting directory
place_in_queue(dir_queue, start_path);
//Start the timer
struct timeval start;
gettimeofday(&start, NULL);
//Let's get parallel up in here
#pragma omp parallel num_threads(num_threads) shared(dir_queue, file_queue, num_found) private(num_threads)//num_files_per_queue_access, num_dirs_per_queue_access
{
//Do the search, yo.
omp_grepr(to_find, num_threads, &num_found, dir_queue, file_queue,num_files_per_queue_access,num_dirs_per_queue_access,file_queue_min_size);
}
//Stop timer here and determine the elapsed time
struct timeval stop;
gettimeofday(&stop, NULL);
printf("OPENMP Overall execution time = %fs. \n", (float)(stop.tv_sec - start.tv_sec + (stop.tv_usec - start.tv_usec)/(float)1000000));
printf("OPENMP The string %s was found %d times within the file system. \n\n", to_find , num_found);
}
开发者ID:JulianKemmerer,项目名称:Drexel-ECEC622-Assignment1,代码行数:54,代码来源:omp_crew.c
示例5: main
int main()
{
int pData; //用来保存出队的元素值
//创建队列并进行入队测试
PQUEUE pS1 = create_queue();
PQUEUE pS2 = create_queue();
push(pS1,pS2,4);
push(pS1,pS2,5);
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
if(pop(pS1,pS2,&pData))
printf("%d is pop out\n",pData);
else
printf("Stack is empty,can not pop\n");
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
push(pS1,pS2,6);
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
push(pS1,pS2,7);
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
if(pop(pS1,pS2,&pData))
printf("%d is pop out\n",pData);
else
printf("Stack is empty,can not pop\n");
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
if(pop(pS1,pS2,&pData))
printf("%d is pop out\n",pData);
else
printf("Stack is empty,can not pop\n");
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
if(pop(pS1,pS2,&pData))
printf("%d is pop out\n",pData);
else
printf("Stack is empty,can not pop\n");
printf("the length of pS1: %d\n",length(pS1));
printf("the length of pS2: %d\n",length(pS2));
if(pop(pS1,pS2,&pData))
printf("%d is pop out\n",pData);
else
printf("Stack is empty,can not pop\n");
return 0;
}
开发者ID:abe360,项目名称:Algorithm-exercise,代码行数:48,代码来源:QueueToStack.cpp
示例6: console_device
void* console_device(void * arg) {
uint32_t scancode;
iorq_t iorq;
int i;
char c;
char * aux;
memset(&keybd_device, 0, sizeof(device_t));
strcpy(keybd_device.ln_link.name, "org.era.dev.console");
keybd_device.iorq_queue = create_queue(10, sizeof(iorq_t));
keybd_queue = create_queue(1, sizeof(uint32_t));
register_interrupt_handler(IRQ1, &keypress_isr);
monitor_writexy(0,24, " 1", 7, 0);
for(;;) {
queue_recv(keybd_device.iorq_queue, &iorq, QM_BLOCKING);
if(iorq.io_desc == DC_READ) {
i = 0;
aux = (char *) iorq.io_dptr;
memset(aux, 0, iorq.io_sz);
while(1) {
queue_recv(keybd_queue, &scancode, QM_BLOCKING);
c = kbdus[scancode];
if (c == '\n')
break;
if ((c == '\b') && (i > 0)) {
aux[i] = '\0';
i--;
monitor_put('\b');
continue;
}
if (c == 0 || c == '\t' || i == (iorq.io_sz - 1))
continue;
if(isprintable(c) ) {
aux[i++] = c;
monitor_put(c);
}
}
monitor_put('\n');
aux[i] = '\0';
queue_send(iorq.io_response, NULL, QM_NONBLOCKING);
}
}
}
开发者ID:renax1991,项目名称:krypton-os-remake,代码行数:48,代码来源:console.c
示例7: main
/*
* Function: int main(int argc, char args[])
* Description: process main function
* Input: argc: parameter number
* args: parameter value array
* Output: none
* Return: function exit status
* Others: none
*/
int main( )
{
Queue * q;
Ele * ele;
q = create_queue( show_ele, delete_ele );
ele = create_ele( 28, "liwei", 10, "hust++life" );
in_queue( q, ele );
ele = create_ele( 24, "lijia", 10, "hust++acon" );
in_queue( q, ele );
ele = create_ele( 26, "lijing", 10, "hust++acon" );
in_queue( q, ele );
queue_show( q );
printf( "=============\n" );
ele = out_queue( q );
show_ele( ele );
ele = out_queue( q );
show_ele( ele );
ele = out_queue( q );
show_ele( ele );
ele = out_queue( q );
show_ele( ele );
}
开发者ID:braveyly,项目名称:codefactory,代码行数:41,代码来源:test_queue.c
示例8: main
int main(){
queue_t *queue;
int i = 0;
int v = 0;
queue = create_queue();
if (queue == NULL){
fprintf(stderr,"Error creating queue\n");
return -EXIT_FAILURE;
}
assert (deq(&v,queue)==0); /*deque an empty queue, print "Queue is empty"*/
for (i = 0; i < 32; ++i)
assert (enq(5,queue)==1); /*fill the queue with 5*/
for (i = 0; i < 32; ++i)
assert (queue->value[i]==5); /*check the entire queue*/
assert (enq(5, queue)==0); /*enque a full queue, print "Queue is full"*/
assert (deq(&v, queue)==1); /*deque the first element*/
assert (enq(6, queue)==1); /*enque 6*/
for (i = 0; i < 32; i++)
assert(deq(&v,queue)==1);
assert (v==6); /*the last element should be 6*/
return EXIT_SUCCESS;
}
开发者ID:binhqnguyen,项目名称:cs5460,代码行数:29,代码来源:problem_6.c
示例9: main
int main()
{
int data_de = 0; //用来保存出队的元素值
//创建队列并进行入队测试
PQUEUE pS = create_queue();
en_queue(pS,2);
en_queue(pS,4);
en_queue(pS,6);
traverse_queue(pS);
//出队测试
if(de_queue(pS,&data_de))
printf("delete succeed,the deleted data is: %d\n",data_de);
else
printf("queue is empty! delete falied!\n");
traverse_queue(pS);
//销毁队列测试
destroy_queue(pS);
printf("queue destroyed!\n");
traverse_queue(pS);
return 0;
}
开发者ID:melanc,项目名称:algorithms,代码行数:25,代码来源:queue.c
示例10: TEST
TEST(PRIORITY_QUEUE,FULL){
//try to get the full status of a non existent queue
RESULT result = is_full(424234);
EXPECT_EQ(result.code,TICKET_INVALID);
//fill up the queue
WELCOME_PACKET packet = create_queue();
//if(packet.result.code == SUCCESS){
for(int i = 0; i < MAXIMUM_NUMBER_OF_ELEMENTS_IN_A_QUEUE-1; i++){
ELEMENT e = {i,i%10};
EXPECT_EQ(enqueue(e,packet.ticket).code,SUCCESS);
EXPECT_EQ(is_full(packet.ticket).code,QUEUE_IS_NOT_FULL);
}
ELEMENT e = {3,3};
enqueue(e,packet.ticket);
EXPECT_EQ(is_full(packet.ticket).code,QUEUE_IS_FULL);
enqueue(e,packet.ticket);
EXPECT_EQ(is_full(packet.ticket).code,QUEUE_IS_FULL);
enqueue(e,packet.ticket);
EXPECT_EQ(is_full(packet.ticket).code,QUEUE_IS_FULL);
//delete the queue then try to get the full status
delete_queue(packet.ticket);
EXPECT_EQ(is_full(packet.ticket).code,TICKET_INVALID);
}
开发者ID:dwa012,项目名称:CSCI6990-priorityqueue,代码行数:34,代码来源:priority_queue_test.c
示例11: calloc
/**
* @brief Start new A/V session. There can only be one session at the time. If you register more
* it will result in undefined behaviour.
*
* @param messenger The messenger handle.
* @param userdata The agent handling A/V session (i.e. phone).
* @param video_width Width of video frame.
* @param video_height Height of video frame.
* @return ToxAv*
* @retval NULL On error.
*/
ToxAv *toxav_new( Tox* messenger, ToxAvCodecSettings* codec_settings)
{
ToxAv *av = calloc ( sizeof(ToxAv), 1);
if (av == NULL)
return NULL;
av->messenger = (Messenger *)messenger;
av->msi_session = msi_init_session(av->messenger);
av->msi_session->agent_handler = av;
av->rtp_sessions[0] = av->rtp_sessions [1] = NULL;
/* NOTE: This should be user defined or? */
av->j_buf = create_queue(codec_settings->jbuf_capacity);
av->cs = codec_init_session(codec_settings->audio_bitrate,
codec_settings->audio_frame_duration,
codec_settings->audio_sample_rate,
codec_settings->audio_channels,
codec_settings->video_width,
codec_settings->video_height,
codec_settings->video_bitrate);
return av;
}
开发者ID:iShift,项目名称:ProjectTox-Core,代码行数:38,代码来源:toxav.c
示例12: sequential_BFS
/// returns array of distances from source
int* sequential_BFS(int *C, int *R, int v, int src)
{
Queue *q = create_queue(v);
int *dist = (int*)malloc(sizeof(int)*v);
for (int i = 0; i < v; ++i)
{
dist[i] = -1;
}
dist[src] = 0;
enqueue(q, src);
int a, b;
while (!empty(q))
{
a = dequeue(q);
for (int j = R[a]; j < R[a + 1]; ++j)
{
b = C[j];
if (dist[b] == -1)
{
dist[b] = dist[a] + 1;
enqueue(q, b);
}
}
}
return dist;
}
开发者ID:rosiakh,项目名称:PGwZO,代码行数:32,代码来源:Sequential_BFS.c
示例13: PriorityQueuetoString
void PriorityQueuetoString(fifo_queue *theArray) {
//fifo_queue *theArray = thePQ->startOfArray;
int i;
for (i = 0; i < NumberOfPriorities; i++ ) {
printf("Q%d:", i);
//FIFOQueuetoString((theArray + i));
fifo_queue *tempqueue = create_queue();
fifo_queue *queue = &theArray[i];
//printf("is_empty %d", is_empty(queue));
//printf("not is_empty %d", !is_empty(queue));
while (!is_empty(queue)) {
//printf("size before dequeue %d", get_size(queue));
PCB_p temp = dequeue(queue);
//toStringShort(temp);
printf("P%d", temp->pid);
enqueue(tempqueue, temp);
if (!is_empty(queue)){
printf("->");
} else {
printf("-");
}
}
printf("*");
//put the data back in the original queue
while (!is_empty(tempqueue)) {
enqueue(queue, dequeue(tempqueue));
}
printf("\n");
}
}
开发者ID:WinterLion,项目名称:422projects,代码行数:31,代码来源:PriorityQueue.c
示例14: test_get_elements_queue
int test_get_elements_queue(){
int value1 = 1;
int value2 = 2;
int value3 = 3;
void *ptr;
Queue *queue = create_queue(sizeof(int));
add(queue, &value1);
add(queue, &value2);
add(queue, &value3);
print_all_elements(queue);
printf("\n-- Removing --\n");
while(1){
ptr = get(queue);
if(ptr != NULL){
printf("removing: %d\n", *((int*)ptr));
}else{
printf("Queue Empty\n");
break;
}
}
free(queue);
return 0;
}
开发者ID:frelei,项目名称:data-struct-c,代码行数:27,代码来源:queue-test.c
示例15: test_OneElementQueue
void
test_OneElementQueue(void) {
queue* q = create_queue();
TEST_ASSERT_NOT_NULL(q);
element e = {"string", 3};
element* e_ptr = debug_get_node(sizeof(element));
enqueue(q, e_ptr);
*e_ptr = e;
TEST_ASSERT_FALSE(empty(q));
TEST_ASSERT_NOT_NULL(queue_head(q));
TEST_ASSERT_EQUAL(1, get_no_of_elements(q));
element* e_ptr_returned = dequeue(q);
TEST_ASSERT_NOT_NULL(e_ptr_returned);
TEST_ASSERT_EQUAL_STRING(e_ptr_returned->str, "string");
TEST_ASSERT_EQUAL_PTR(e_ptr_returned, e_ptr);
TEST_ASSERT_EQUAL(0, get_no_of_elements(q));
TEST_ASSERT_TRUE(empty(q));
TEST_ASSERT_NULL(dequeue(q));
destroy_queue(q);
}
开发者ID:qicny,项目名称:freebsd,代码行数:26,代码来源:ntp_prio_q.c
示例16: main
//driver code
int main()
{
// Let cache can hold X pages
unsigned int X = 4;
Queue* q = create_queue( X );
// Let Y different pages can be requested (pages to be
// referenced are numbered from 0 to 9
unsigned int Y = 10;
Hash* hash = create_hash( Y );
// Let us refer pages 1, 2, 3, 1, 4, 5
reference_page( q, hash, 1);
reference_page( q, hash, 2);
reference_page( q, hash, 3);
reference_page( q, hash, 1);
reference_page( q, hash, 4);
reference_page( q, hash, 5);
// Let us print cache frames after the above referenced pages
printf ("%d ", q->front->page_no);
printf ("%d ", q->front->next->page_no);
printf ("%d ", q->front->next->next->page_no);
printf ("%d ", q->front->next->next->next->page_no);
return 0;
}
开发者ID:NikhitaGaonkar,项目名称:Practice-C-codes,代码行数:28,代码来源:LRU_cache.c
示例17: main
int main()
{
struct priority_queue *queue = create_queue(10);
if (queue == NULL)
printf("create_queue error\n");
insert_queue(queue, 10, (struct huff_table*)10);
insert_queue(queue, 11, (struct huff_table*)11);
insert_queue(queue, 8, (struct huff_table*)8);
insert_queue(queue, 3, (struct huff_table*)3);
insert_queue(queue, 7, (struct huff_table*)7);
insert_queue(queue, 15, (struct huff_table*)15);
uint32_t priority = 0;
struct huff_table *table = NULL;
while (best_queue(queue, &priority, &table)) {
printf("Table = %ld\n", (uint64_t)table);
delete_queue(queue);
}
free_queue(queue);
return EXIT_SUCCESS;
}
开发者ID:nejmd,项目名称:JPEG,代码行数:28,代码来源:test_file.c
示例18: test_empty
void test_empty() {
queue *q = create_queue();
assert(empty(q));
destroy_queue(q);
}
开发者ID:jwasham,项目名称:practice-c,代码行数:7,代码来源:tests_queue_linked_list.c
示例19: main
int
main() {
queue_t *q;
item_t t;
int i,j;
q = create_queue(3);
i = 0;
while( fscanf(stdin, "%d", &t) == 1 ) {
if( ! t ) {
if( ! i ) fprintf(stderr, "queue is alread empty\n");
else {
fprintf(stdout, "%d\n", dequeue(q));
i--;
}
} else {
enqueue(q, t);
i++;
}
}
for( j = 0; j < i; j++ ) {
fprintf(stdout, "%d\n", dequeue(q));
}
destroy_queue(q);
return 0;
}
开发者ID:BelfordZ,项目名称:cAlgs,代码行数:28,代码来源:cqueue.c
示例20: BFS
static void BFS(struct graph_s *graph, struct vertex_s *s) {
/* assumes graph is an adjacency list */
int i;
struct listnode_s *adj;
struct vertex_s *u, *v;
struct queue_s *Q;
Q = create_queue(graph->num_vertices);
for (i = 0; i < graph->num_vertices; ++i) {
graph->vertices[i]->color = WHITE;
graph->vertices[i]->distance = 0;
graph->vertices[i]->predecessor = NULL;
}
s->color = GRAY;
enqueue(Q, s);
while (!is_empty(Q)) {
u = dequeue(Q);
for (adj = u->adj; adj; adj = adj->next) {
v = adj->v;
if (v->color == WHITE) {
v->color = GRAY;
v->distance = u->distance+1;
v->predecessor = u;
enqueue(Q, v);
}
}
u->color = BLACK;
}
free(Q->vertices);
free(Q);
}
开发者ID:CodeR57,项目名称:algorithms-1,代码行数:35,代码来源:graph.c
注:本文中的create_queue函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论