int main(int argc, char *argv[]) { init_queue(); put(10); put(9); put(8); put(7); put(8); put(9); put(2); put(110); put(13094); put(989899); print_queue(); get(); get(); get(); print_queue(); return 0; }
static int read_file_queues(struct seq_file *file, void *data) { struct ieee80211_hw *hw = dev_get_drvdata(file->private); struct ath_softc *sc = hw->priv; struct ath_txq *txq; int i; static const char *qname[4] = { "VO", "VI", "BE", "BK" }; for (i = 0; i < IEEE80211_NUM_ACS; i++) { txq = sc->tx.txq_map[i]; seq_printf(file, "(%s): ", qname[i]); print_queue(sc, txq, file); } seq_puts(file, "(CAB): "); print_queue(sc, sc->beacon.cabq, file); return 0; }
void test_queue(void) { queue q; init_queue(&q); push(&q, 5); push(&q, 0); push(&q, 1); push(&q, 2); print_queue(&q); }
int main() { int i; init_queue(); for(i=1;i<10;i++){ append_tail(2*i); } print_queue(); for(i=1;i<6;i++){ delete_head(); } print_queue(); for(i=15;i<30;i++){ append_tail(2*i); } print_queue(); return 0; }
main(void) { int n; init_queue(); enqueue(1); print_queue(); enqueue(2); print_queue(); enqueue(3); print_queue(); n = dequeue(); print_queue(); enqueue(4); print_queue(); }
int main(int argc, char *argv[]) { int list[MAX]; init_queue(list); printf("Queue from start:\n"); print_queue(list); printf("Queue after adding 7,8,9 in turn\n"); input(list, 7); input(list, 8); input(list, 9); print_queue(list); printf("Queue after adding 21\n"); input(list, 21); print_queue(list); printf("Queue after removing 7\n"); remove(list); print_queue(list); printf("Querying the queue\n"); queue_status(list); printf("Filling the queue\n"); input(list, 9); input(list, 9); print_queue(list); queue_status(list); printf("Attempting to add to queue, this is the returned int: %d \n", input(list, 200)); print_queue(list); remove(list); printf("Removing and attempting again, this is the returned int: %d \n", input(list, 200)); }
int main(int argc, const char *argv[]) { queue_t* a; int data; int i; a = (queue_t*)malloc(sizeof(queue_t)); new_queue(a, 10); print_queue(a); pushq(a, 2); print_queue(a); popq(a, &data); print_queue(a); pushq(a, 3); print_queue(a); for(i = 0; i < a->size + 3; i++) { pushq(a, i); print_queue(a); } for(i = 0; i < a->size + 3; i++) { popq(a, &data); print_queue(a); printf("data: %d\n", data); } del_queue(a); free(a); return 0; }
void pok_sched_reorder_asynch_list() { pok_sched_asynch_event_t* current_temporary = POK_CURRENT_PARTITION.head_asynch_temporary; pok_sched_asynch_event_t* current_asynch = POK_CURRENT_PARTITION.head_asynch_queue; uint64_t current_timestamp; while (current_temporary != POK_NULL) { current_timestamp = current_temporary->timestamp; pok_sched_asynch_event_t* prev = POK_NULL; while (current_asynch != POK_NULL && current_asynch->timestamp < current_timestamp) { prev = current_asynch; current_asynch = current_asynch->next; } current_temporary->previous = prev; current_temporary->next = current_asynch; if (prev != POK_NULL) prev->next = current_temporary; else POK_CURRENT_PARTITION.head_asynch_queue = current_temporary; //update head of queue if (current_asynch != POK_NULL) current_asynch->previous = current_temporary; current_temporary = current_temporary->next; } POK_CURRENT_PARTITION.head_asynch_temporary = POK_NULL; #ifdef POK_NEEDS_DEBUG_O1 if (POK_CURRENT_PARTITION.head_asynch_empty != POK_NULL || POK_CURRENT_PARTITION.head_asynch_temporary != POK_NULL || POK_CURRENT_PARTITION.head_asynch_queue != POK_NULL) { printf("**********************************************************************\n"); printf("DEBUG_O1::REORDERED ASYNCH QUEUES:\n"); printf("** Empty queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_empty); printf("** Temporary queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_temporary); printf("** Actual queue: ");print_queue(POK_CURRENT_PARTITION.head_asynch_queue); printf("**********************************************************************\n"); } #endif }
int main(int argc, char** argv) { char action[MAX_LINE_LENGTH]; char* input = (char*)malloc(MAX_VALUE_SIZE * sizeof(char)); int priority1; int priority2; PQueue* queue = NULL; SubPQueue* node1 = NULL; PQueue* node2 = NULL; char Ch; if (argc != 2){ printf("\nInsufficient arguments.\n"); return 0; } FILE* in = NULL; in = fopen(argv[1], "r"); if (in == NULL){ printf("File cannot be opened.\n"); return 0; } while (!feof(in)){ fscanf(in, "%s", action); if (strcmp(action, "enqueue") == 0){ fscanf(in, "%d%d%s", &priority1, &priority2, input); enqueue(&queue, priority1, priority2, input); } // else if(strcmp(action, "dequeue") == 0){ // } // else if(strcmp(action, "print") == 0){ // } // else{ // printf("\nInvalid Command: %s", action); // // } if (feof(in)) break; } print_queue(queue); return 0; }
/*! do stuff every 1/4 second called from clock_10ms(), do not call directly */ static void clock_250ms(void) { if (heaters_all_zero()) { if (psu_timeout > (30 * 4)) { power_off(); } else { ATOMIC_START psu_timeout++; ATOMIC_END } } temp_heater_tick(); ifclock(clock_flag_1s) { #ifdef DISPLAY display_clock(); #endif temp_residency_tick(); if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) { // current position update_current_position(); sersendf_P(PSTR("Pos: %lq,%lq,%lq,%lq,%lu\n"), current_position.axis[X], current_position.axis[Y], current_position.axis[Z], current_position.axis[E], current_position.F); // target position sersendf_P(PSTR("Dst: %lq,%lq,%lq,%lq,%lu\n"), movebuffer[mb_tail].endpoint.axis[X], movebuffer[mb_tail].endpoint.axis[Y], movebuffer[mb_tail].endpoint.axis[Z], movebuffer[mb_tail].endpoint.axis[E], movebuffer[mb_tail].endpoint.F); // Queue print_queue(); // newline serial_writechar('\n'); } // temperature /* if (temp_get_target()) temp_print();*/ } #ifdef TEMP_INTERCOM start_send(); #endif }
int main(int argc, char **argv) { int values_A[] = { -5, 42, 36, 24, }; int values_B[] = { 200, 300, 400, }; struct cds_wfcq_head head_A; /* Queue A head */ struct cds_wfcq_tail tail_A; /* Queue A tail */ struct cds_wfcq_head head_B; /* Queue B head */ struct cds_wfcq_tail tail_B; /* Queue B tail */ int ret = 0; cds_wfcq_init(&head_A, &tail_A); /* Enqueue nodes into A. */ ret = enqueue_values(&head_A, &tail_A, values_A, CAA_ARRAY_SIZE(values_A)); if (ret) goto end; cds_wfcq_init(&head_B, &tail_B); /* Enqueue nodes into B. */ ret = enqueue_values(&head_B, &tail_B, values_B, CAA_ARRAY_SIZE(values_B)); if (ret) goto end; print_queue(&head_A, &tail_A, "queue A content before splice"); print_queue(&head_B, &tail_B, "queue B content before splice"); /* * Splice nodes from A into B. */ printf("Splicing queue A into queue B\n"); (void) cds_wfcq_splice_blocking(&head_B, &tail_B, &head_A, &tail_A); print_queue(&head_A, &tail_A, "queue A content after splice"); print_queue(&head_B, &tail_B, "queue B content after splice"); end: cds_wfcq_destroy(&head_A, &tail_A); return ret; }
int main() { char step[11] = "_mDxcDjg9P4"; push_id("song 1"); push_id("song 2"); push_id("song 3"); print_queue(); struct song *s; for (int i = 0; i < 4; i++) { s = pop_id(); printf("%11s\n", s ? s->video_id : "(null)"); } }
void bfs(int source_node_bfs) { enqueue(source_node_bfs); while((queue_count)!=0) { visit_index=1; source_node_bfs=dequeue(); save_source_bfs[iter_bfs][1]=source_node_bfs; visited_bfs[source_node_bfs]=-1; for(int i=1;i<=vertex_num;i++) { if(adj_mat[source_node_bfs][i]!=0 && visited_bfs[i]!=-1) { enqueue(i); save_visited_bfs[iter_bfs][visit_index++]=i; visited_bfs[i]=-1; } } print_queue(); iter_bfs++; } for(int i=1;i<=iter_bfs;i++) for(int j=1;j<=i;j++) black_mat[i][j]=save_source_bfs[j][1]; printf("\n\n\n Source save:\n\n\n"); for(int i=1;i<=vertex_num;i++) {for(int j=1;j<=vertex_num;j++) printf("%d\t",black_mat[i][j]); printf("\n"); } printf("\n\n\n"); printf("Visit Save:\n\n\n"); for(int i=1;i<=vertex_num;i++) {for(int j=1;j<=vertex_num;j++) printf("%d\t",save_visited_bfs[i][j]); printf("\n"); } }
int main(){ insert(5); insert(7); insert(3); insert(8); insert(12); insert(14); insert(118); print_queue(); printf("\nextractMax:\n"); int max = extractMax(); printf("\nThe Max is %d.\n",max); print_queue(); printf("\nincrease, index is [5] and value is [10]:\n"); increase(5,10); print_queue(); printf("\nChange value, index is [5] and value is [10]:\n"); change(5,10); print_queue(); return 0; }
int main(int ac, char **av) { Queue *queue; int i; queue = NULL; i = 0; while (i < ac) { push_queue(&queue, av[i]); ++i; } printf("----------print----------\n"); print_queue(queue); return (0); }
int main(void) { int data; int action; struct cell *front; struct cell *rear; front = NULL; rear = front; print_menu(&action); while (action != END) { switch (action) { case ENQUEUE: data = rand()%10; rear = enqueue(data, front, rear); if(!front) { front = rear; } printf("%d has been enqueued.\n",data); break; case DEQUEUE: if ( !front ) { printf("Queue is empty, so you can't take the data.\n"); } else if(front == rear) { dequeue(front,rear,&data); front = NULL; } else { front = dequeue(front, rear, &data); printf("%d has been dequeued.\n", data); } break; default: break; } print_queue(front); print_menu(&action); } return 0; }
int main(int argc, char *argv[]) { char s[100]; QUEUE *q = NULL; Q_ELEMENT_WHAT *qpt; int i, n; q = init_queue(q, what_cmp); qpt = (Q_ELEMENT_WHAT *) malloc(sizeof(double)); while (fgets(s, 99, stdin) != NULL) { switch (s[0]) { case 'n': n = atoi(strtok(s+1, " ")); printf("n: %d\n", n); if (n < 1) break; qpt = (Q_ELEMENT_WHAT *) malloc(n * sizeof(Q_ELEMENT_WHAT)); printf("enqueued "); for (i = 0; i < n; i++) { qpt[i] = atof(strtok(NULL, " \n")); printf("%g ", qpt[i]); } printf("\n"); enqueue(q, qpt, n); break; case 'e': *qpt = atof(s+1); enqueue(q, qpt, 1); break; case 'd': printf("d %g\n", dequeue(q)); break; case 'p': print_queue(q); break; case 'q': free_queue(q); exit(0); break; default: printf("%s", Q_HELP); break; } } return 0; }
int main() { struct Q* Q; struct Q_elem* elem_add; struct Q_elem* elem_del; int i =0; char input; scanf("%c",&input); Init(&Q); while(input != 'e') { switch(input) { case 'a': elem_add = (struct Q_elem*) malloc(sizeof(struct Q_elem)); // elem_add->data = i; i++; printf("Element Added\n"); Add(Q,elem_add); break; case 'd': elem_del = Del(Q); //printf("%d",elem_del->data); printf("Element Deleted\n"); if (elem_del != NULL) free(elem_del); break; case 'r': Rotate(Q); break; case 'p': print_queue(Q); break; default: printf("Invalid Input\n"); break; } scanf("%c",&input); scanf("%c",&input); } }
/* clean up after Ctrl+C or shutdown */ static void clean_on_quit(int sig) { struct cn_strct *tp; int i; #if DEBUG_VERBOSE == 2 printf("\n\n\n\n\nPRINTING QUEUE: \n"); print_queue(_Queue_head, _Queue_count); printf("PRINTING QUEUE_LIST: \n"); print_list(_Queue_tail); printf("PRINTING FREEs: \n"); print_list(_Free_conns); printf("PRINTING BUSYs: \n"); print_list(_Busy_conns); #endif while (NULL != _Free_conns) { tp = _Free_conns->c_next; free(_Free_conns->data_buf_head); free(_Free_conns); _Free_conns = tp; } while (NULL != _Busy_conns) { tp = _Busy_conns->c_next; #if DEBUG_VERBOSE == 2 print_cn(tp); #endif free(_Busy_conns->data_buf_head); close(_Busy_conns->net_socket); free(_Busy_conns); _Busy_conns = tp; } close(_Master_sock); _Master_sock = -1; printf("Graceful exit done after signal: %d\n", sig); /* cleanup the threads */ for (i = 0; i < WORKER_THREADS; i++) { pthread_cancel(_Workers[i].thread); } exit(0); }
int main() { Queue* queue = setup_queue(); printf("%d\n", queue->length); enqueue(queue, 1); printf("%d\n", queue->length); enqueue(queue, 2); printf("%d\n", queue->length); int* a = dequeue(queue); int* b = dequeue(queue); printf("%d\n", *a); printf("%d\n", *b); print_queue(queue); free(queue); return 0; }
int main() { // Example use of priority queue pqueue queue; node n1, n2, n3; n1.data = 1; n1.cost = 1; n2.data = 0; n2.cost = 0; n3.data = 3; n3.cost = 3; init_queue(&queue); enqueue(&queue, &n1); enqueue(&queue, &n2); enqueue(&queue, &n3); print_queue(&queue); return 0; }
int main(int argc, char *argv[]){ TABLE *table = create_table(); read_table(stdin, table); // print_table(table); PIECE_LIST *list = create_piece_list(table); QUEUE *queue = create_queue(); list_moves(table, queue, list); print_queue(queue); //printf("-----------------------------------------------------\n"); // print_table(table); delete_queue(&queue); delete_list(&list); //printf("-----------------------------------------------------\n"); // print_table(table); delete_table(&table); return 0; }
/*! do stuff every 1/4 second called from clock_10ms(), do not call directly */ void clock_250ms() { #ifndef NO_AUTO_IDLE if (temp_all_zero()) { if (steptimeout > (30 * 4)) { power_off(); } else { uint8_t save_reg = SREG; cli(); CLI_SEI_BUG_MEMORY_BARRIER(); steptimeout++; MEMORY_BARRIER(); SREG = save_reg; } } #endif ifclock(clock_flag_1s) { if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) { // current position sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F); // target position sersendf_P(PSTR("Dst: %ld,%ld,%ld,%ld,%lu\n"), movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.E, movebuffer[mb_tail].endpoint.F); // Queue print_queue(); // newline serial_writechar('\n'); } // temperature /* if (temp_get_target()) temp_print();*/ } #ifdef TEMP_INTERCOM start_send(); #endif }
void SLang_exit_error (SLFUTURE_CONST char *fmt, ...) { va_list ap; print_queue (); va_start (ap, fmt); if (SLang_Exit_Error_Hook != NULL) { (*SLang_Exit_Error_Hook) (fmt, ap); exit (1); } if (fmt != NULL) { vfprintf (stderr, fmt, ap); fputs ("\n", stderr); fflush (stderr); } va_end (ap); exit (1); }
int main(void){ printf("文字を一つ入力して下さい\n"); printf("i: 後に続いて入力されたデータをキューの末尾に挿入する.\n"); printf("キューが満杯の場合はその旨をディスプレイに出力する.\n"); printf("d: キューの先頭のデータを削除する.\n"); printf("キューが空の場合はその旨をディスプレイに出力する.\n"); printf("p: キューのデータを先頭から順番にディスプレイに出力する.\n"); printf("q: 実行を終了する.\n"); printf("上記以外: i,d,p,または q を入力する旨のメッセージをディスプレイに出力する.\n"); int n; char c; init_queue(); while(1){ printf("\n>>>"); scanf("%1s", &c); switch (c) { case 'i': scanf("%d", &n); enqueue(n); break; case 'd': dequeue(); break; case 'p': print_queue(); break; case 'q': exit(0); break; default: printf("i,d,p,またはqを入力して下さい。\n"); } } }
void clock_250ms() { if (steptimeout > (30 * 4)) { power_off(); } else steptimeout++; ifclock(CLOCK_FLAG_1S) { if (debug_flags & DEBUG_POSITION) { // current position sersendf_P(PSTR("Pos: %ld,%ld,%ld,%ld,%lu\n"), current_position.X, current_position.Y, current_position.Z, current_position.E, current_position.F); // target position sersendf_P(PSTR("Dst: %ld,%ld,%ld,%ld,%lu\n"), movebuffer[mb_tail].endpoint.X, movebuffer[mb_tail].endpoint.Y, movebuffer[mb_tail].endpoint.Z, movebuffer[mb_tail].endpoint.E, movebuffer[mb_tail].endpoint.F); // Queue print_queue(); } // temperature /* if (temp_get_target()) temp_print();*/ } }
/* My beautiful main */ int main(int argc, char * argv[]){ /* Declare instance data */ int i; PCB **headOfQueue; PCB **tailOfQueue; PCB pcbNode; /* allocate space on the stack for the head and tail */ headOfQueue = (PCB**)malloc(sizeof(PCB*)); tailOfQueue = (PCB**)malloc(sizeof(PCB*)); /* Start the pointers out as null */ *headOfQueue = 0; *tailOfQueue = 0; /* for loop to populate the gueue and assign ID a random value */ for(i=0; i<100; i++){ /* Initialize the PCB variable values to 0 */ pcbNode.ID = rand()% 10000 + 1; enqueue(headOfQueue,tailOfQueue,pcbNode); } /* Prints the nodes ID in the queue */ print_queue(*tailOfQueue); /* Prints the number of nodes in the queue*/ printf("There are %d elements in the queue.\n", size_of_queue(*tailOfQueue)); /* Clears the queue */ clear_queue(headOfQueue,tailOfQueue); /* Reprints the number of nodes to ensure it was cleared*/ printf("There are %d elements in the queue.\n", size_of_queue(*tailOfQueue)); return(0); }
/* queue_test: test queue functions, data_type_s is int here */ static void queue_test(void) { struct queue *q; q = init_queue(); print_queue(q); enqueue(q, 1); enqueue(q, 2); enqueue(q, 3); print_queue(q); dequeue(q); enqueue(q, 4); print_queue(q); dequeue(q); print_queue(q); dequeue(q); print_queue(q); dequeue(q); print_queue(q); }
void main(void) { int i; init_queue(); printf("\nPut 5, 4, 7, 8, 2, 1"); put(5); put(4); put(7); put(8); put(2); put(1); print_queue(); printf("\nGet"); i = get(); print_queue(); printf("\n getting value is %d", i); printf("\nPut 3, 2, 5, 7"); put(3); put(2); put(5); put(7); print_queue(); printf("\nNow queue is full, put 3"); put(3); print_queue(); printf("\nInitialize queue"); clear_queue(); print_queue(); printf("\nNow queue is empty, get"); i = get(); print_queue(); printf("\n getting value is %d", i); }
/** * \brief Init scheduling service */ void pok_sched_init (void) { #ifdef POK_NEEDS_PARTITIONS #if defined (POK_NEEDS_ERROR_HANDLING) || defined (POK_NEEDS_DEBUG) /* * We check that the total time of time frame * corresponds to the sum of each slot */ uint64_t total_time; uint8_t slot; total_time = 0; for (slot = 0 ; slot < POK_CONFIG_SCHEDULING_NBSLOTS ; slot++) { total_time = total_time + pok_sched_slots[slot]; } if (total_time != POK_CONFIG_SCHEDULING_MAJOR_FRAME) { #ifdef POK_NEEDS_DEBUG printf ("[DEBUG]\n ERROR: Major frame is not compliant with all time slots\n"); #endif #ifdef POK_NEEDS_ERROR_HANDLING pok_kernel_error (POK_ERROR_KIND_KERNEL_CONFIG); #endif } #endif /* POK_NEEDS_ERROR_HANDLING) || defined (POK_NEEDS_DEBUG) */ #endif /* POK_NEEDS_PARTITIONS */ pok_sched_current_slot = 0; /* POK_CONFIG_SCHEDULING_MAJOR_FRAME = sum of all scheduling slots */ pok_sched_next_major_frame = POK_CONFIG_SCHEDULING_MAJOR_FRAME; pok_sched_next_deadline = pok_sched_slots[0]; // start to execute the first partition pok_current_partition = pok_sched_slots_allocation[0]; #ifdef POK_NEEDS_SCHED_O1 uint32_t i; for(i=0; i<POK_CONFIG_NB_THREADS; i++) pok_thread_ids_to_pos_map[i]=i; // *************************** ASYNCH EVENTS QUEUES **************************************** // // adjust initial slot and major frame values to work with interval timer scheduling (start-up) pok_sched_current_slot--; pok_sched_next_major_frame++; uint8_t part=0; uint8_t index=0; uint8_t index_low=0; uint8_t counter; while (part < POK_CONFIG_NB_PARTITIONS) { index = pok_asynch_events[part]; //init pointers of queue elements for (counter = index_low; counter < index_low + index; counter++) { if (counter -1 >= index_low) asynch_queue[counter].previous = &(asynch_queue[counter-1]); else asynch_queue[counter].previous = POK_NULL; if (counter +1 < index) asynch_queue[counter].next = &(asynch_queue[counter+1]); else asynch_queue[counter].next = POK_NULL; } if (index > 0) { pok_partitions[part].head_asynch_queue = POK_NULL; pok_partitions[part].head_asynch_empty = &(asynch_queue[index_low]); pok_partitions[part].head_asynch_temporary = POK_NULL; } #ifdef POK_NEEDS_DEBUG_O1 printf("[DEBUG_O1]\t QUEUE for partition %d starts from index %d\n", part, index_low); print_queue(pok_partitions[part].head_asynch_empty); #endif index_low += index; part++; } #endif }