Need help with these /** * function: sq_seat() * description: if the queue is no
ID: 3673020 • Letter: N
Question
Need help with these
/**
* function: sq_seat()
* description: if the queue is non-empty, it removes the first
* entry from (front of queue) and returns the
* buzzer ID.
* Note that the returned buzzer can now be re-used.
*
* If the queue is empty (nobody to seat), -1 is returned to
* indicate this fact.
*
* RUNTIME REQUIREMENT: O(1)
*/
extern int sq_seat(SQ *q);
/**
* function: sq_kick_out()
*
* description: Some times buzzer holders cause trouble and
* a bouncer needs to take back their buzzer and
* tell them to get lost.
*
* Specifially:
*
* If the buzzer given by the 2nd parameter is
* in the queue, the buzzer is removed (and the
* buzzer can now be re-used) and 1 (one) is
* returned (indicating success).
*
* If the buzzer isn't actually currently in the
* queue, the queue is unchanged and 0 is returned
* (indicating failure).
*
* RUNTIME REQUIREMENT: O(1)
*/
extern int sq_kick_out(SQ *q, int buzzer);
/**
* function: sq_take_bribe()
* description: some people just don't think the rules of everyday
* life apply to them! They always want to be at
* the front of the line and don't mind bribing
* a bouncer to get there.
*
* In terms of the function:
*
* - if the given buzzer is in the queue, it is
* moved from its current position to the front
* of the queue. 1 is returned indicating success
* of the operation.
* - if the buzzer is not in the queue, the queue
* is unchanged and 0 is returned (operation failed).
*
* RUNTIME REQUIREMENT: O(1)
*/
extern int sq_take_bribe(SQ *q, int buzzer);
Explanation / Answer
in this program they used a data structure called queue to anf if queue contains any value it gives buzzer sound
until the queue is empty.
if queue is empty buzzer returns -1 value saying queue doesnt contaning any value.
and this program is applied for bribers who dont care about thier lifes and bribes all the time and they always want to be first.
so it is applied to them
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.