I have a given function prototype in which I need to design a data structure to complete it:
The function OccupiedOrNot() will return 1 if there is something at the direction of location loc, otherwise 0 is returned. Of course, at some locations something, say 'X' have been marked already.
In order to do this, I define another data structure:
But for every given location, OccupiedOrNot() needs to read the file to decide if marked or not. If I want the new defined structure elementT to store all marked location globally in advance, then I don't know how to pass it to OccupiedOrNot().
I think this approach is not good enough. The key is the first code snippet can't not be changed. You are free to modify the data structure in the second code snippet.
Code:
typedef struct {
int x, y;
} locationT;
typedef enm{North, South, East, West} directionT;
int OccupiedOrNot(locationT loc, directionT dir);
The function OccupiedOrNot() will return 1 if there is something at the direction of location loc, otherwise 0 is returned. Of course, at some locations something, say 'X' have been marked already.
In order to do this, I define another data structure:
Code:
typedef struct {
locationT locT;
char ch;
} elementT;
// then something like this:
int OccupiedOrNot(locationT loc, directionT dir)
{
elementT eleT;
// read in marked locations to eleT by calling
// another function void readlocation(filename)
if (eleT.ch == 'X') return(1);
else return(0);
}
But for every given location, OccupiedOrNot() needs to read the file to decide if marked or not. If I want the new defined structure elementT to store all marked location globally in advance, then I don't know how to pass it to OccupiedOrNot().
I think this approach is not good enough. The key is the first code snippet can't not be changed. You are free to modify the data structure in the second code snippet.