GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 11-Dec-2004, 13:49
The_Kingpin The_Kingpin is offline
New Member
 
Join Date: Oct 2004
Posts: 13
The_Kingpin is on a distinguished road

Help creating lists of pointers


Hi,

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:

Code:
#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 */ }Pnode; PtrListItem messSnt[MAX_MES_SNT+1]; PtrListItem messTrs[MAX_MES_TRS+1]; PtrListItem messRec[MAX_MES_REC+1];


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[1] (the ptrNode member of this new listitem will point on this node), add an a list item to messTrs[5] (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).

Code:
void CreateLists(PtrNode childTree) { if (childTree) { /* We need to go through the tree in in an ascending order */ /* Find the first element of the tree */ CreateLists(childTree->left); /* 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 */ CreateLists(childTree->right); } }


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.
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,
Frank
 
 

Recent GIDBlogHalfway done! by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
isThere pointers in PHP sajuat MySQL / PHP Forum 1 20-Nov-2006 09:18
help with delete function using pointers!!! wbsquared03 C++ Forum 0 29-Nov-2004 16:32
Problem with the function creating updating a linked list nkhambal C Programming Language 3 28-Oct-2004 20:45
Help with C++ pointers Mjkramer21 C++ Forum 23 18-Apr-2004 07:53
Passing Pointers To Pointers in Functions elumira C Programming Language 8 05-Mar-2004 21:23

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:25.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.