intqueue_size(queue_t*queue){queue_t*temp_q=queue_create();intsize=0;while(!queue_is_empty(queue)){enqueue(temp_q,dequeue(queue));size++;}while(!queue_is_empty(temp_q)){//put back into original stack
enqueue(queue,dequeue(temp_q));}queue_free(temp_q);returnsize;}boolequal_queues(queue_t*q1,queue_t*q2){queue_t*temp_1=queue_create();queue_t*temp_2=queue_create();intsize1=queue_size(q1);intsize2=queue_size(q2);if(size1!=size2){queue_free(temp_1);queue_free(temp_2);return0;}while(!queue_is_empty(q1)){//check for equality, store all values
intq1curr=dequeue(q1);intq2curr=dequeue(q2);printf("gets vals");if(q1curr!=q2curr){queue_free(temp_1);queue_free(temp_2);return0;}else{enqueue(temp_1,q1curr);enqueue(temp_2,q2curr);}}while(!queue_is_empty(temp_1)){//put back into original queues
intdata=dequeue(temp_1);enqueue(q1,data);data=dequeue(temp_2);enqueue(q2,data);}queue_free(temp_1);queue_free(temp_2);return1;}
5 - copy_queue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
queue_t*copy_queue(queue_t*orig){queue_t*copy_q=queue_create();queue_t*temp_q=queue_create();while(!queue_is_empty(orig)){enqueue(temp_q,dequeue(orig));//put into temp
}while(!queue_is_empty(temp_q)){intdata=dequeue(temp_q);//allows to build both
enqueue(orig,data);enqueue(copy_q,data);}returncopy_q;}
intstack_size(stack_t*s){// implement me
stack_t*temp_stack=stack_create();intsize=0;while(!stack_is_empty(s)){stack_push(temp_stack,stack_pop(s));size++;}while(!stack_is_empty(temp_stack)){//put back into original stack
stack_push(s,stack_pop(temp_stack));}stack_free(temp_stack);returnsize;}boolstack_equal(stack_t*s1,stack_t*s2){// implement me
stack_t*temp_1=stack_create();stack_t*temp_2=stack_create();intsize1=stack_size(s1);intsize2=stack_size(s2);if(size1!=size2){stack_free(temp_1);stack_free(temp_2);return0;}while(!stack_is_empty(s1)){//s1 and s2 have to be same size due to above return if conditional
intval1=stack_pop(s1);intval2=stack_pop(s2);if(val1!=val2){stack_free(temp_1);stack_free(temp_2);return0;}else{stack_push(temp_1,val1);stack_push(temp_2,val2);}}while(!stack_is_empty(temp_1)){//put back into original stacks
intdata=stack_pop(temp_1);stack_push(s1,data);data=stack_pop(temp_2);stack_push(s2,data);}stack_free(temp_1);stack_free(temp_2);return1;}
voidreverse_queue(queue_t*queue){LL_t*list=malloc(sizeof(LL_t));//temp to store in reverse
LLcreate(list);while(!queue_is_empty(queue)){//adds to head to reverse
intdata=dequeue(queue);LL_add_to_head(list,data);}while(list→head!=NULL){intdata=LL_remove_from_head(list);enqueue(queue,data);printf("qdata = %d\n",data);}LL_free(list);}