![]() |
|
#1
|
|||
|
|||
treeSplit() attempted solution, needs checking!Hey, for the treeSplit() function problem I mentioned earlier (Ive added the attachment of the problem again, just in case you havent seen it), and Ive produced a not-debugged solution as a .txt file (pasted below). I would really appreciate it if you read thru the attachment and my code, and provide me some feedback on how I can optimize stuff in there and improve clarity etc. Its not debugged, but right now I just need to know it its more or less correct code-wise and if I could optimize it in some areas! Im a little skeptical over my use of the boolean flags, I mite've used em incorrectly! Im sorry if I somehow breached some guidelines of posting.
please note: treeCount() is a function I wrote already, it returns total number of nodes in a tree or subtree, taking its root as an input. rightChild() and leftChild() access functions are also available to be called, taking any pointer as an input. (its just, tree ->right, tree->left) my code is attached as treesplit() solution thx a lot! |
|
#2
|
|||
|
|||
Re: treeSplit() attempted solution, needs checking!Have you tried compiling this? It's got a boatload of syntax errors.
1. Functions, loops, if-then statement blocks are begun and ended with curly braces { }, not parentheses ( ). 2. need a semicolon after int B 3. when passing parameters to functions, you don't need to give the type. should be: int treesize = treeCount(treeRoot); 4. Shouldn't have a semicolon after if (treesize%2) because this will do unexpected things. CPP / C++ / C Code:
5. In the while condition, "less than or equal to" is <=, not =< 6. Usually spaces don't matter in C++, but two-character operators have to be kept together. != not ! =, >= not > =, == not = = Another note: how are leftChild and rightChild defined, and what do they return? If they just return newly constructed TreePtrs, assigning to them won't work. I haven't really gone through the algorithm -- the best way to test it is to actually test it. Iron out the syntax errors, get the code to compile, and see if it works! A final note: your code's really not that long, you should include it in your post between [c++] and [/c++] tags because many people are loathe to open attachments. |
|
#3
|
|||
|
|||
Re: treeSplit() attempted solution, needs checking!hey, yeah but Im not tryin to debug it right now, I realise theres loads of syntax errors in there, the proper brace buttons not functioning on my comp, so I didnt use it, I just need to have a paper version. Actually this is part of a question of a practise exam paper, so youre not even meant to compile it. I have to simply get the algorithm more or less right on code and optimize it as much as possible! But still, Ill try debug it later on!
thx |
|
#4
|
|||
|
|||
Re: treeSplit() attempted solution, needs checking!hey sorry, forgot to say thanks for the corrections, I definitely made some silly mistakes! the corrections will be invaluable when I debug this thing
|
Recent GIDBlog
Developing GUIs with wxPython (Part 3) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Content Management Solution Needed | eventbroker | Member Announcements, Advertisements & Offers | 0 | 07-Jun-2006 07:57 |
| Need A Solution for Spanish Translation? | eventbroker | Miscellaneous Programming Forum | 0 | 07-Jun-2006 06:37 |
| HTML checking and validation software | 4dept | Web Design Forum | 2 | 11-Feb-2005 14:23 |
| fltk-2.0 cvs | Plumb | FLTK Forum | 20 | 13-Nov-2004 07:10 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The