コード例 #1
0
ファイル: bintree.cpp プロジェクト: StevenU8/BinaryTree
	void BinTree::bstreeToArrayHelper(NodeData* TreeArray[], int &index, Node* current)
	{
		if(current == NULL) {
			return;
		}
		
		bstreeToArrayHelper(TreeArray, index, current->left);
		TreeArray[index] = current->data;
		index++;
		bstreeToArrayHelper(TreeArray, index, current->right);
	}
コード例 #2
0
ファイル: bintree.cpp プロジェクト: andyt338/C-Projects
//---------------------------------------------------------------------------
// bstreeToArrayHelper
// Traverse tree inorder and store Nodedata* in tempArray.
int BinTree::bstreeToArrayHelper(Node* current, NodeData* tempArray[])
{
    if(current == NULL) // base case
        return 0;
    // perform on left child
    int left = bstreeToArrayHelper(current->left, tempArray);
    NodeData* temp;
    temp = current->data; // store current's data in temp
    current->data = NULL;
    *(tempArray + left) = temp; // inset NodeData into array
    temp = NULL;
    // perform on right child
    int right = bstreeToArrayHelper(current->right, tempArray + left + 1);
    return left + right + 1; // return position
}
コード例 #3
0
ファイル: bintree.cpp プロジェクト: StevenU8/BinaryTree
////////////////////////////////////////////////////////////////////////////////////////////////////
// bstreeToArray: Fills in an array with data from the tree
// Pre Conditions: Tree and array are properly inialized
// Post Conditions: Array of NodeData is filled in
////////////////////////////////////////////////////////////////////////////////////////////////////
	void BinTree::bstreeToArray(NodeData* TreeArray[])
	{
		int index = 0;
		bstreeToArrayHelper(TreeArray, index, root);
		makeEmpty();
	}
コード例 #4
0
ファイル: bintree.cpp プロジェクト: andyt338/C-Projects
//---------------------------------------------------------------------------
// bstreeToArray
// Turns the BSTree into an array and destroys the BST.
void BinTree::bstreeToArray(NodeData* tempArray[])
{
    bstreeToArrayHelper(root, tempArray);
    makeEmpty();
}