static int print_queue(c_pqueue ps) { c_vector tmpvt; __c_vector(&tmpvt, int_comparer); printf("queue is : \n"); while(!c_queue_empty(ps)) { int * tmp = c_queue_front(ps); printf("front is : %d, size is : %d, back is : %d\n", *tmp, c_queue_size(ps), *(int *)c_queue_back(ps)); c_queue_pop(ps); c_vector_push_back(&tmpvt, tmp); } // recover queue do { c_iterator iter = c_vector_begin(&tmpvt); c_iterator end = c_vector_end(&tmpvt); for(; !ITER_EQUAL(iter, end); ITER_INC(iter)) { c_queue_push(ps, ITER_REF(iter)); } } while(0); __c_rotcev(&tmpvt); return 0; }
void delete_all_memory(void) { while( top != NULL ) stack_pop(); while( front != NULL ) queue_pop(); while( c_front != NULL ) c_queue_pop(); }
int main() { int i = 0; c_queue *que = c_queue_create(dump, release, sizeof(int)); for (i = 0; i < 10; ++i) { c_queue_push(que, &i); } printf("c_queue.size == %d\n", c_queue_size(que)); for (i = 0; i < 5; ++i) { c_queue_pop(que); } for (i = 10; i < 15; ++i) { c_queue_push(que, &i); } c_queue *clone = c_queue_clone(que); while (!c_queue_is_empty(clone)) { printf("%d, ", *(int*)c_queue_top(clone)); c_queue_pop(clone); } c_queue_destroy(clone); printf("\n"); c_queue_clear(que); for (i = 0; i < 5; ++i) { c_queue_push(que, &i); } while (!c_queue_is_empty(que)) { printf("%d, ", *(int*)c_queue_top(que)); c_queue_pop(que); } printf("\n"); c_queue_destroy(que); return 0; }
static int clear_queue(c_pqueue ps) { while(!c_queue_empty(ps)) { c_queue_pop(ps); } return 0; }
bool make_circle(int *buf) { int command = 0, operand = 0; int i = 0, count = 0; for(i = 1; i <= buf[0]; ++i) { switch(buf[i]) { case 0: if(count > C_QUEUE_SIZE) return false; if( !c_queue_push(buf[++i]) ) return false; count++; break; case 1: c_queue_pop(); count--; break; default: break; } } return true; }