|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
I want to write a function
int Listofleaves (Tree tree,List* list) which recieve a binary tree -"tree"(the input) and a list pointer "list"(output)...the function supposed to return the trees leaves nodes(nodes with no children) from right to left as a linked list(!) in "list"...and also return at the end the sum of all those leaves.... anyone knows??? thanks for help people |
| Sponsored Links |
|
|
|
|||||
|
To add a node on your linked list, you first have to check the pointer to the start of the list. If this' pointer to the next node is NULL, you set the next-pointer to the new node.
Then you have to set the pointer to the end of the lists next-pointer to the new node, set the next-pointer in the new node to NULL, and then point the whole end-pointer to the new node. Of course, when you want to have the value of the binary trees node too, you have to set that value in the new node of the linked list. If your linked list doesn't have an end-pointer, but only a start-pointer (which most actually have), then it's a bit harder to implement. You still have to check if the start-pointer is NULL, but if it isn't (it already had been used) you have to go through the whole list, and check if you're at the end. Here's an example: Code:
void addNodeAtEnd(node *newNode)
{
node *temporaryNode = new node;
if(startNode == NULL)
startNode = newNode;
else
{
temporaryNode = startNode;
while(temporaryNode->next != NULL)
temporaryNode = temporaryNode->next;
temporaryNode->next = newNode;
}
delete temporaryNode;
}
Just make a fast search with some of the many search engines. Last edited by v0id; 05-03-2007 at 10:42 AM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sending mail to a group of people (Mailing list support/Emulation) | nesrait | easyContact | 1 | 07-25-2007 09:48 PM |
| GMail Vulnerable To Contact List Hijacking | TcM | Computer Software/OS | 28 | 02-17-2007 11:36 AM |
| Binary, Decimal, Hex, the Manual way!! | TcM | Tutorials | 22 | 01-10-2007 01:06 AM |
| Binary? | NeedHelp | Managed C++ | 4 | 07-27-2006 03:59 PM |
| Binary Conversion in VB | roger | Visual Basic Programming | 0 | 06-01-2006 11:50 AM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |