Anyone? ha
I don't know how exactly to implement this, should i make the function return a pointer to the next 2 nodes?
Can you have a function return 2 values? Can you have it return a pointer to a structure?
Thanks!
Anyone? ha
I don't know how exactly to implement this, should i make the function return a pointer to the next 2 nodes?
Can you have a function return 2 values? Can you have it return a pointer to a structure?
Thanks!
"Anyone can aspire to greatness if they try hard enough."
- Me
And here's where it's implemented:Code:int countNodes(node *startPoint) { if(startPoint == NULL) { //No Nodes = 0 return 0; }else{ int count = 1; count += countNodes(startPoint->cLeft); count += countNodes(startPoint->cRight); return count; } }
I'm getting segmentation faults like crazy! haCode:createTree(root, numbers, size); //TEMPORARY cout<<"The Tree Has "<<countNodes(root)<<" nodes.\n"; //END TEMPORARY
Here's the rest of the program should you guys need it:
Thanks!Code:#include <iostream> using namespace std; //Node Structure struct node { int data; //Data of the Node (int) node *parent; //Pointer to the Parent Node node *cLeft; //Pointer to the child node on the left node *cRight; //Pointer to the child node on the right }; //Global Variables node *root; node *current; //Function Prototypes void createTree(node *start, int numbers[], int size); //Creates the Tree struct node *addPly(node *parent, int numbers[], int cArrayPoint); //Used by createTree, adds another ply/level to the tree void displayTree(); //Displays the Tree void searchTree(int number); //Searches the tree for a certain number void sortNumbers(int numbers[], int *pNum[], int size); //Sorts an Array of numbers from Lowest to Highest bool assignPointersArray(int numbers[], int *pNum[], int size); int countNodes(node *startPoint); int main() { root = new node; //Clear out memory for the Root node int numbers[10]; //Array of numbers to be represented by the tree int *pNum[10]; //Array of Pointers to the array of numbers int size; //Size of the two previous arrays size = (sizeof(numbers)/sizeof(numbers[0])); if(assignPointersArray(numbers, pNum, size) == false)//Function which assigns pointers to the numbers { return 1; //Fatal Error } //Get Numbers cout<<"Please Enter 10 Numbers..."<<endl; for(int g=0; g<10; g++) { cout<<"Element "<<(g+1)<<": "; cin>>numbers[g]; } sortNumbers(numbers, pNum, size); //TEMPORARY - DISPLAY THE LIST cout<<"\n"<<"SORTED LIST:\n"; for(int disp=0; disp<size; disp++) { cout<<"Element "<<disp+1<<": "<<numbers[disp]<<endl; } cin.ignore(); //END TEMPORARY createTree(root, numbers, size); //TEMPORARY cout<<"The Tree Has "<<countNodes(root)<<" nodes.\n"; //END TEMPORARY displayTree(); cin.ignore(); return 0; } void createTree(node *start, int numbers[], int size) { //Create Tree Function //Assumes the list has been sorted properly, from lowest to highest //Every node to the left of the parent is less than, and vice verse //Determine the starting point int startPoint; if(size % 2 == 0) { startPoint = size/2; }else{ startPoint = (int)((size/2) - 0.5); } start->data = numbers[startPoint]; //Create the Plies of the tree node *tempL; node *tempR; node *tempP; node *tempP2; tempP = addPly(start, numbers, startPoint); tempL = tempP->cLeft; tempR = tempP->cRight; for(int i=0; i<size; i++) { tempP = addPly(tempL, numbers, startPoint-(i+1)); tempP2 = addPly(tempR, numbers, startPoint+(i+1)); tempL = tempP->cLeft; tempR = tempP2->cRight; } } struct node *addPly(node *parent, int numbers[], int cArrayPoint) { node *nLeft; node *nRight; nLeft = new node; nRight = new node; if(numbers[cArrayPoint-1]) { nLeft->data = numbers[cArrayPoint-1]; parent->cLeft = nLeft; }else{ parent->cLeft = NULL; delete nLeft; } if(numbers[cArrayPoint+1]) { nRight->data = numbers[cArrayPoint+1]; parent->cRight = nRight; }else{ parent->cRight = NULL; delete nRight; } return parent; } void sortNumbers(int numbers[], int *pNum[], int size) { //Sort Number Array Function - LO-HI int temp1, temp2; for(int i=0; i<size; i++) { for(int s=0; s+1<size; s++) { if(numbers[s] > numbers[s+1]) { temp1 = numbers[s]; temp2 = numbers[s+1]; numbers[s] = temp2; numbers[s+1] = temp1; }else if(numbers[s] < numbers[s+1]) { //Nothing - Stay the Same }else if(numbers[s] == numbers[s+1]) { //Nothing - Stay the Same }else{ //Nothing - Stay the Same } } } //Replace the old numbers[] array with the new, sorted one for(int r=0; r<size; r++) { *pNum[r] = numbers[r]; } } void displayTree() { //Display Tree Function } bool assignPointersArray(int numbers[], int *pNum[], int size) { //Assign Pointers to Array Elements Function if(sizeof(numbers) != sizeof(pNum)) return false; else{ for(int i=0; i<size; i++) { pNum[i] = &numbers[i]; } return true; } } int countNodes(node *startPoint) { if(startPoint == NULL) { //No Nodes = 0 return 0; }else{ int count = 1; count += countNodes(startPoint->cLeft); count += countNodes(startPoint->cRight); return count; } }
"Anyone can aspire to greatness if they try hard enough."
- Me
(I'm working upwards here.) countNodes() looks okay. assignPointersArray() still has this line, which as I said earlier is useless:
Just leave it out. (Or pass both lengths and compare them.) You can't determine how many elements are in an array if you are passed the array. You have to get the calling function to pass the number of elements in it. (Assuming you're trying to do what I think you are.)Code:if(sizeof(numbers) != sizeof(pNum)) return false;
displayTree() is obviously a stub.
sortNumbers() still isn't doing things optimally. Take a look at this: http://www.cprogramming.com/tutorial.../sorting1.html
addPly() seems to assume that cArrayPoint is >0 and <max-1. I don't know if that is a valid assumption or not. At least mention it if it is.
In createTree() . . .
The highlighted line won't do what you want. Since size is odd, dividing it by two will truncuate the number. (5/2 is 2.) Then you subtract .5 from that, and that becomes truncuated. In effect, the resulting number will be two less than if you'd used the code in the even branch of the if statement. I don't think that's what you want, but maybe it is. If it is there are easier ways to go about it.Code:if(size % 2 == 0) { startPoint = size/2; }else{ startPoint = (int)((size/2) - 0.5); }
A debugger is a great tool for debugging segmentation faults. If you're using Dev-C++, it comes with (an annoying implementation of) GDB, the GNU debugger. There is a tutorial about its use here: http://www.cprogramming.com/gdbtutorial.html
Last edited by dwks; 04-04-2007 at 11:55 AM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Okay i'll omit those lines and fix those things. I'm using MSVC Express.
And i'm still lost, ha
Thanks for the help! Keep it comin'!
EDIT-----
All the segmentation faults are stemming from the countNodes() function
Last edited by Junior89; 04-04-2007 at 12:52 PM.
"Anyone can aspire to greatness if they try hard enough."
- Me
(Code like that also occurs in createTree().) You only need one temporary variable to swap two variables (and none in Perl ):Code:temp1 = numbers[s]; temp2 = numbers[s+1]; numbers[s] = temp2; numbers[s+1] = temp1;
Also:Code:temp = one; one = two; two = temp;
As far as I can see, the only reason you created pNum was so that you could modify the values of the array in other functions, like sortNumbers(). Well, there's an easier way to do that.Code:int numbers[10]; //Array of numbers to be represented by the tree int *pNum[10]; //Array of Pointers to the array of numbers // [...] if(assignPointersArray(numbers, pNum, size) == false)// [...] { return 1; //Fatal Error } // [...] bool assignPointersArray(int numbers[], int *pNum[], int size) { //Assign Pointers to Array Elements Function if(sizeof(numbers) != sizeof(pNum)) return false; else{ for(int i=0; i<size; i++) { pNum[i] = &numbers[i]; } return true; } }
You wouldn't believe how long it took me to figure that out when I first started programming. I was writing a backup program, dbackup . . .Code:const int array_size = 10; void called(int (*array)[array_size]); void driver(void) { int array[array_size] = {0}; /* initalize all elements to zero */ called(&array); } void called(int (*array)[array_size]) { /* now the contents of array[] can be modified like so: */ (*array)[0] = 0; }
Last edited by dwks; 04-04-2007 at 12:57 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks! I'll try to implement that, i've learned so much about pointers with all this, ha, more than i have with binary trees
Lol. Thanks!
"Anyone can aspire to greatness if they try hard enough."
- Me
Still getting all these segmentation faults with the countNodes() functionCode:#include <iostream> using namespace std; //Node Structure struct node { int data; //Data of the Node (int) node *parent; //Pointer to the Parent Node node *cLeft; //Pointer to the child node on the left node *cRight; //Pointer to the child node on the right }; //Global Variables node *root; node *current; //Function Prototypes void createTree(node *start, int numbers[], int size); //Creates the Tree struct node *addPly(node *parent, int numbers[], int cArrayPoint); //Used by createTree, adds another ply/level to the tree void displayTree(); //Displays the Tree void searchTree(int number); //Searches the tree for a certain number void sortNumbers(int numbers[], int *pNum[], int size); //Sorts an Array of numbers from Lowest to Highest bool assignPointersArray(int numbers[], int *pNum[], int size, int pSize); int countNodes(node *startPoint); int main() { root = new node; //Clear out memory for the Root node const int array_size = 10; int numbers[array_size]; //Array of numbers to be represented by the tree int *pNum[array_size]; //Array of Pointers to the array of numbers int size; int pSize; //Size of the two previous arrays size = (sizeof(numbers)/sizeof(numbers[0])); pSize = (sizeof(pNum)/sizeof(pNum[0])); if(assignPointersArray(numbers, pNum, size, pSize) == false)//Function which assigns pointers to the numbers { return 1; //Fatal Error } //Get Numbers cout<<"Please Enter "<<array_size<<" Numbers..."<<endl; for(int g=0; g<10; g++) { cout<<"Element "<<(g+1)<<": "; cin>>numbers[g]; } sortNumbers(numbers, pNum, size); //TEMPORARY - DISPLAY THE LIST cout<<"\n"<<"SORTED LIST:\n"; for(int disp=0; disp<size; disp++) { cout<<"Element "<<disp+1<<": "<<numbers[disp]<<endl; } cin.ignore(); //END TEMPORARY createTree(root, numbers, size); //TEMPORARY cout<<"The Tree Has "<<countNodes(root)<<" nodes.\n"; //END TEMPORARY displayTree(); cin.ignore(); return 0; } void createTree(node *start, int numbers[], int size) { //Create Tree Function //Assumes the list has been sorted properly, from lowest to highest //Every node to the left of the parent is less than, and vice verse //Determine the starting point int startPoint; if(size % 2 == 0) { startPoint = size/2; }else{ startPoint = (int)(size/2); } start->data = numbers[startPoint]; //Create the Plies of the tree node *tempL; node *tempR; node *tempP; node *tempP2; tempP = addPly(start, numbers, startPoint); tempL = tempP->cLeft; tempR = tempP->cRight; for(int i=0; i<size; i++) { tempP = addPly(tempL, numbers, startPoint-(i+1)); tempP2 = addPly(tempR, numbers, startPoint+(i+1)); tempL = tempP->cLeft; tempR = tempP2->cRight; } } struct node *addPly(node *parent, int numbers[], int cArrayPoint) { node *nLeft; node *nRight; nLeft = new node; nRight = new node; if(numbers[cArrayPoint-1] != NULL) { nLeft->data = numbers[cArrayPoint-1]; parent->cLeft = nLeft; }else{ parent->cLeft = NULL; delete nLeft; } if(numbers[cArrayPoint+1] != NULL) { nRight->data = numbers[cArrayPoint+1]; parent->cRight = nRight; }else{ parent->cRight = NULL; delete nRight; } return parent; } void sortNumbers(int numbers[], int *pNum[], int size) { //Sort Number Array Function - LO-HI int temp1, temp2; for(int i=0; i<size; i++) { for(int s=0; s+1<size; s++) { if(numbers[s] > numbers[s+1]) { temp1 = numbers[s]; temp2 = numbers[s+1]; numbers[s] = temp2; numbers[s+1] = temp1; }else if(numbers[s] < numbers[s+1]) { //Nothing - Stay the Same }else if(numbers[s] == numbers[s+1]) { //Nothing - Stay the Same }else{ //Nothing - Stay the Same } } } //Replace the old numbers[] array with the new, sorted one for(int r=0; r<size; r++) { *pNum[r] = numbers[r]; } } void displayTree() { //Display Tree Function } bool assignPointersArray(int numbers[], int *pNum[], int size, int pSize) { //Assign Pointers to Array Elements Function if(size != pSize) return false; else{ for(int i=0; i<size; i++) { pNum[i] = &numbers[i]; } return true; } } int countNodes(node *startPoint) { if(startPoint == NULL) { //No Nodes = 0 return 0; }else{ int count = 1; count += countNodes(startPoint->cLeft); count += countNodes(startPoint->cRight); return count; } }
The problem probably lies in the createTree and addPly functions
Thoughts?
"Anyone can aspire to greatness if they try hard enough."
- Me
Your program crashes in this line
when you call addPly with cArrayPoint 0.Code:if(numbers[cArrayPoint-1] != NULL)
numbers are not pointers so I guess you want to check if parent has a left child.
Mayby like that
This one creates an illegal access tooCode:if(cArrayPoint > 0 )
You would have to pass the size of numbers to addPly to see if there is a right childCode:if(numbers[cArrayPoint+1] != NULL)
Kurt
I'm trying to see if that element of the array actually exists.
"Anyone can aspire to greatness if they try hard enough."
- Me
Then how should i go about doing it?
"Anyone can aspire to greatness if they try hard enough."
- Me
the answer is in post #23
Kurt
I think i fixed it, but i'm still getting segmentation faults, with the addPly() funciton i think.
Code:#include <iostream> using namespace std; //Node Structure struct node { int data; //Data of the Node (int) node *parent; //Pointer to the Parent Node node *cLeft; //Pointer to the child node on the left node *cRight; //Pointer to the child node on the right }; //Global Variables node *root; node *current; //Function Prototypes void createTree(node *start, int numbers[], int size); //Creates the Tree struct node *addPly(node *parent, int numbers[], int cArrayPoint); //Used by createTree, adds another ply/level to the tree void displayTree(); //Displays the Tree void searchTree(int number); //Searches the tree for a certain number void sortNumbers(int numbers[], int *pNum[], int size); //Sorts an Array of numbers from Lowest to Highest bool assignPointersArray(int numbers[], int *pNum[], int size, int pSize); int countNodes(node *startPoint); int main() { root = new node; //Clear out memory for the Root node const int array_size = 10; int numbers[array_size]; //Array of numbers to be represented by the tree int *pNum[array_size]; //Array of Pointers to the array of numbers int size; int pSize; //Size of the two previous arrays size = (sizeof(numbers)/sizeof(numbers[0])); pSize = (sizeof(pNum)/sizeof(pNum[0])); if(assignPointersArray(numbers, pNum, size, pSize) == false)//Function which assigns pointers to the numbers { return 1; //Fatal Error } //Get Numbers cout<<"Please Enter "<<array_size<<" Numbers..."<<endl; for(int g=0; g<10; g++) { cout<<"Element "<<(g+1)<<": "; cin>>numbers[g]; } sortNumbers(numbers, pNum, size); //TEMPORARY - DISPLAY THE LIST cout<<"\n"<<"SORTED LIST:\n"; for(int disp=0; disp<size; disp++) { cout<<"Element "<<disp+1<<": "<<numbers[disp]<<endl; } cin.ignore(); //END TEMPORARY createTree(root, numbers, size); //TEMPORARY cout<<"The Tree Has "<<countNodes(root)<<" nodes.\n"; //END TEMPORARY displayTree(); cin.ignore(); return 0; } void createTree(node *start, int numbers[], int size) { //Create Tree Function //Assumes the list has been sorted properly, from lowest to highest //Every node to the left of the parent is less than, and vice verse //Determine the starting point int startPoint; if(size % 2 == 0) { startPoint = size/2; }else{ startPoint = (int)(size/2); } start->data = numbers[startPoint]; //Create the Plies of the tree node *tempL; node *tempR; node *tempP; node *tempP2; tempP = addPly(start, numbers, startPoint); tempL = tempP->cLeft; tempR = tempP->cRight; for(int i=0; i<size; i++) { tempP = addPly(tempL, numbers, startPoint-(i+1)); tempP2 = addPly(tempR, numbers, startPoint+(i+1)); tempL = tempP->cLeft; tempR = tempP2->cRight; } } struct node *addPly(node *parent, int numbers[], int cArrayPoint) { node *nLeft; node *nRight; nLeft = new node; nRight = new node; if(cArrayPoint-1 >= 0) { nLeft->data = numbers[cArrayPoint-1]; parent->cLeft = nLeft; }else{ parent->cLeft = NULL; delete nLeft; } if(cArrayPoint+1 <= 10) { nRight->data = numbers[cArrayPoint+1]; parent->cRight = nRight; }else{ parent->cRight = NULL; delete nRight; } return parent; } void sortNumbers(int numbers[], int *pNum[], int size) { //Sort Number Array Function - LO-HI int temp1, temp2; for(int i=0; i<size; i++) { for(int s=0; s+1<size; s++) { if(numbers[s] > numbers[s+1]) { temp1 = numbers[s]; temp2 = numbers[s+1]; numbers[s] = temp2; numbers[s+1] = temp1; }else if(numbers[s] < numbers[s+1]) { //Nothing - Stay the Same }else if(numbers[s] == numbers[s+1]) { //Nothing - Stay the Same }else{ //Nothing - Stay the Same } } } //Replace the old numbers[] array with the new, sorted one for(int r=0; r<size; r++) { *pNum[r] = numbers[r]; } } void displayTree() { //Display Tree Function } bool assignPointersArray(int numbers[], int *pNum[], int size, int pSize) { //Assign Pointers to Array Elements Function if(size != pSize) return false; else{ for(int i=0; i<size; i++) { pNum[i] = &numbers[i]; } return true; } } int countNodes(node *startPoint) { if(startPoint == NULL) { //No Nodes = 0 return 0; }else{ int count = 1; count += countNodes(startPoint->cLeft); count += countNodes(startPoint->cRight); return count; } }
"Anyone can aspire to greatness if they try hard enough."
- Me
I think your problem is here somewhere, where you call addPly():
First of all, both branches of the if(size%2...) statement do the same thing, so why not get rid of the conditional code?Code:void createTree(node *start, int numbers[], int size) { //Create Tree Function //Assumes the list has been sorted properly, from lowest to highest //Every node to the left of the parent is less than, and vice verse //Determine the starting point int startPoint; if(size % 2 == 0) { startPoint = size/2; }else{ startPoint = (int)(size/2); } start->data = numbers[startPoint]; //Create the Plies of the tree node *tempL; node *tempR; node *tempP; node *tempP2; tempP = addPly(start, numbers, startPoint); tempL = tempP->cLeft; tempR = tempP->cRight; for(int i=0; i<size; i++) { tempP = addPly(tempL, numbers, startPoint-(i+1)); tempP2 = addPly(tempR, numbers, startPoint+(i+1)); tempL = tempP->cLeft; tempR = tempP2->cRight; } }
Secondly, shouldn't
be <size/2 or <startPos or something? Thirdly, what if tempP->cLeft or Right is NULL? BOOM, segmentation fault. Check to see if they're NULL, and if so, exit the loop.Code:for(int i=0; i<size; i++)
Last edited by dwks; 04-05-2007 at 04:40 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
More segmentation faults!!!!! I hate seg faults, haha.Code:#include <iostream> using namespace std; //Node Structure struct node { int data; //Data of the Node (int) node *parent; //Pointer to the Parent Node node *cLeft; //Pointer to the child node on the left node *cRight; //Pointer to the child node on the right }; //Global Variables node *root; node *current; //Function Prototypes void createTree(node *start, int numbers[], int size); //Creates the Tree struct node *addPly(node *parent, int numbers[], int cArrayPoint); //Used by createTree, adds another ply/level to the tree void displayTree(); //Displays the Tree void searchTree(int number); //Searches the tree for a certain number void sortNumbers(int numbers[], int *pNum[], int size); //Sorts an Array of numbers from Lowest to Highest bool assignPointersArray(int numbers[], int *pNum[], int size, int pSize); int countNodes(node *startPoint); int main() { root = new node; //Clear out memory for the Root node const int array_size = 10; int numbers[array_size]; //Array of numbers to be represented by the tree int *pNum[array_size]; //Array of Pointers to the array of numbers int size; int pSize; //Size of the two previous arrays size = (sizeof(numbers)/sizeof(numbers[0])); pSize = (sizeof(pNum)/sizeof(pNum[0])); if(assignPointersArray(numbers, pNum, size, pSize) == false)//Function which assigns pointers to the numbers { return 1; //Fatal Error } //Get Numbers cout<<"Please Enter "<<array_size<<" Numbers..."<<endl; for(int g=0; g<10; g++) { cout<<"Element "<<(g+1)<<": "; cin>>numbers[g]; } sortNumbers(numbers, pNum, size); //TEMPORARY - DISPLAY THE LIST cout<<"\n"<<"SORTED LIST:\n"; for(int disp=0; disp<size; disp++) { cout<<"Element "<<disp+1<<": "<<numbers[disp]<<endl; } cin.ignore(); //END TEMPORARY createTree(root, numbers, size); //TEMPORARY cout<<"The Tree Has "<<countNodes(root)<<" nodes.\n"; //END TEMPORARY displayTree(); cin.ignore(); return 0; } void createTree(node *start, int numbers[], int size) { //Create Tree Function //Assumes the list has been sorted properly, from lowest to highest //Every node to the left of the parent is less than, and vice verse //Determine the starting point int startPoint; if(size % 2 == 0) { startPoint = size/2; }else{ startPoint = (int)(size/2); } start->data = numbers[startPoint]; //Create the Plies of the tree node *tempL; node *tempR; node *tempP; node *tempP2; tempP = addPly(start, numbers, startPoint); tempL = tempP->cLeft; tempR = tempP->cRight; for(int i=0; i<size/2; i++) { tempP = addPly(tempL, numbers, startPoint-(i+1)); tempP2 = addPly(tempR, numbers, startPoint+(i+1)); if(tempP->cLeft == NULL || tempP->cRight == NULL || tempP2->cLeft == NULL || tempP2->cRight == NULL) { break; } tempL = tempP->cLeft; tempR = tempP2->cRight; } } struct node *addPly(node *parent, int numbers[], int cArrayPoint) { node *nLeft; node *nRight; nLeft = new node; nRight = new node; if(cArrayPoint-1 >= 0) { nLeft->data = numbers[cArrayPoint-1]; parent->cLeft = nLeft; }else{ parent->cLeft = NULL; delete nLeft; } if(cArrayPoint+1 <= 10) { nRight->data = numbers[cArrayPoint+1]; parent->cRight = nRight; }else{ parent->cRight = NULL; delete nRight; } return parent; } void sortNumbers(int numbers[], int *pNum[], int size) { //Sort Number Array Function - LO-HI int temp1, temp2; for(int i=0; i<size; i++) { for(int s=0; s+1<size; s++) { if(numbers[s] > numbers[s+1]) { temp1 = numbers[s]; temp2 = numbers[s+1]; numbers[s] = temp2; numbers[s+1] = temp1; }else if(numbers[s] < numbers[s+1]) { //Nothing - Stay the Same }else if(numbers[s] == numbers[s+1]) { //Nothing - Stay the Same }else{ //Nothing - Stay the Same } } } //Replace the old numbers[] array with the new, sorted one for(int r=0; r<size; r++) { *pNum[r] = numbers[r]; } } void displayTree() { //Display Tree Function } bool assignPointersArray(int numbers[], int *pNum[], int size, int pSize) { //Assign Pointers to Array Elements Function if(size != pSize) return false; else{ for(int i=0; i<size; i++) { pNum[i] = &numbers[i]; } return true; } } int countNodes(node *startPoint) { if(startPoint == NULL) { //No Nodes = 0 return 0; }else{ int count = 1; count += countNodes(startPoint->cLeft); count += countNodes(startPoint->cRight); return count; } }
THese are (again) with the countNodes() function.
I must not be allocating the memory properly or soemthing...
EDIT----------
Yeah the startPoint->cLeft and cRight in the countNodes() function are NULL.
=(
Last edited by Junior89; 04-05-2007 at 06:39 PM.
"Anyone can aspire to greatness if they try hard enough."
- Me