Question: Consider the following function: void mystery ( int num ) { int current; stack * stk = ( stack * ) malloc ( sizeof (

Consider the following function:
void mystery(int num){
int current;
stack *stk =(stack *) malloc(sizeof(stack));
queue *que =(queue *) malloc(sizeof(queue));
while( num >0){
push(stk, num);
num = num -1;
}
while( empty(stk)!=1){
current = pop(stk);
insert(que, current);
printf("%d ", current);
}
printf("
");
while( empty(que)!=1){
current = remove(que);
push(stk, current);
printf("%d ", current);
}
printf("
");
while( empty(stk)!=1){
current = pop(stk);
if( empty(stk)!=1){
insert(que, pop(stk));
}
printf("%d ", current);
}
printf("
");
while( empty(que)!=1){
current = remove(que);
push(stk, current);
printf("%d ", current);
}
free(stk); free(que);
}
Suppose we call mystery(7). What does this print out?
Suppose we replace que with a priority queue. In particular assume that the
function remove removes and returns the largest element of the queue.
What does a call to mystery(7) print out now? show work.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!