Help creating lists of pointers
I have build a binary tree and each node of this tree contains a number of messages sent, message received and messages transmitted. What I want to do is to go through the tree and add the information of each node into a separated list (there's a different list for the 3 type of message).
Now my tree is already build with the correct information and I know how to go through the tree in a fix order. My problem is when it comes to creating the lists. First, I have declared the three of them like this:
#define MAX_MES_SNT 25 /* max number of messages sent */
#define MAX_MES_TRS 250 /* max number of messages transmited */
#define MAX_MES_REC 25 /* max number of messages received */
typedef struct pnode* PtrListItem;
typedef struct pnode
PtrNode ptrNode; /* points on an element of the tree */
PtrListItem next; /* points on the next listitem */
So far, so good I hope. Then, I start reading elements of the tree and this is where I'm bugged. Let's say the first node has 1 sent msg, 5 transmited msg and 2 received msg. I need to add a listitem to the list messSnt (the ptrNode member of this new listitem will point on this node), add an a list item to messTrs (the prtNode member of this new listitem will also points on this node) and same thing for the received msg. This way, once I finish going through the tree, I will have build every lists needed to print my reports.
I started creating the function that build the lists and here's what it looks like (note that I started by doing it only for 1 kind of msg).
If would really appreciate if anyone could tell me how to actually add an item correctly to my lists and if I'm going in the right direction.
void CreateLists(PtrNode childTree)
/* We need to go through the tree in in an ascending order */
/* Find the first element of the tree */
/* Creates a new list item and allocates memory */
PtrListItem PtrCur = (PtrListItem ) malloc (sizeof (Pnode));
PtrCur->ptrNode = childTree;
/* Should add a pointer to the current node into the correct list... */
messSnt[childTree->nbMessSnt] = PtrCur;
PtrCur->next = NULL;
/* Do the right side of the tree */
If you need more information or more code, please let me know and I will post it.
Thanks a lot for your time and support,