Hi again,
I changed the structure to this:
Code:
typedef struct
{
word addr;
byte slot;
byte frame;
}NodeSlotFrame;
struct NSFList
{
NodeSlotFrame nsf;
struct NSFList *next;
};
typedef struct
{
NodeSlotFrame own;
byte nrOfNeighbours;
struct NSFList *neighbours;
byte nrOfHiddenNodes;
struct NSFList *hiddenNodes;
}INF;
And then I allocate new node like this:
Code:
void myfunction()
{
struct NSFList* neighbour = dat.inf.neighbours;
if(dat.inf.nrOfNeighbours == 0)
{
dat.inf.neighbours = (struct NSFList*) malloc(sizeof(struct NSFList));
dat.inf.neighbours->next = NULL; //first node
//Keep the information of new node
memcpy(&dat.inf.neighbours->nsf, &rDat.inf.own, sizeof(NodeSlotFrame));
//Increase the count
dat.inf.nrOfNeighbours++;
return;
}
//SEARCH THE LIST
while (neighbour->next != NULL)
{
...
}
if(newNeighbour == TRUE)
{
//Memeory for new neighbour
neighbour->next = (struct NSFList*) malloc(sizeof(struct NSFList));
neighbour->next->next = NULL; //This is the last node
//Add to the list
memcpy(&neighbour->next->nsf, &rDat.inf.own, sizeof(NodeSlotFrame));
//Increase the count
dat.inf.nrOfNeighbours++;
}
}
I am assuming that this should be correct. if not, please let me know. I have done link lists many times but it's always confusing when it's done in c or c++. I also problem debugging the algorithm in KDevelop with g++ (Which is not the compiler for the actual device) and am not sure where the problem lies. I wish do debug it directly for the device but that is just not possible at the moment...
I can't pass parameters I'm afraid so please accept the there are no functions for adding/removing items. I'm working in NesC, a flavor of C for Wireless Sensor Networks and it doesn't 'allow' passing parameters directly.
Thanks again
Inderjit