Here's My Code:
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(int numbers[]); //Creates the Tree
void addPly(); //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 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);
cin.ignore();
createTree(numbers);
displayTree();
cin.ignore();
return 0;
}
void createTree(int numbers[])
{
//Create Tree Function
}
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<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
}
}
}
//Display Array
for(int j=0; j<size; j++)
{
cout<<"Element "<<(j+1)<<" Equals: "<<numbers[j]<<endl;
}
}
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;
}
}
I'm getting some very interesting results, and a runtime error.
Okay...
First off, it sorts the numbers right, but the first number in the sequence is an enourmous negative number, the other 9 are the first 9 of the array in the proper order.
And after it sorts the numbers and it runs the createTree() function (probably), it says the stack with the numbers array is corrupted i believe.
Thanks for any help ya can give!