A mobile application needs to store the cells that are within range at each time. The number of cells is unknown and changes depending on the device position. Each cell has a unique identifier (positive integer) and a level of signal quality (number between 0 and 100). At each time, the application denotes one of the cells as the “current” (the one offering the highest signal quality). Every certain time, this information is updated depending on the signal quality field.
The following two functions are already implemented in the application:
... new_cell()
. Returns a pointer to a new
cell structure. The result type is the data structure to store the cell
information.
void remove_cell(...)
. Function opposite to
the previous one, receives a pointer to a cell data structure and gets
rid off it. You must call this function to make the data structure
“disappear”.
You have to rite the following code portions:
Define the data structure to store the cell data and declaration of the variables required to stored the application data.
void fill_fields(...)
. Function that assigns
the values given as parameters to the fields of a structure pointed to
by an additional parameter. Decide first the parameters received by the
function and then the code.
void update_current(...)
. Function that
assigns as “current” the one with the higher quality
signal.
What change would you make in the definition of the data structure to store the data in a “circular” form (that is, they are ordered as a circle)?
You may following the steps:
How will you represent the set of cells? Do you know in advance how many cells you have to manipulate?
Define the data structures required to store the set of cells. How do you distinguish the actual cell?
What do you think it should be the prototype of the
function “new_cell
”?
Define the prototype of the
“fill_fields
” function. Write its code.
Implement the “update_current
”
function.
What is the meaning of a “circular structure” and how to implement it in C?