void CTestDoc::Serialize(CArchive& ar)
{
T.Serialize(ar);
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
void BinarySearchTree::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{ // storing code
ar.Write (&Root , sizeof(Root)) ;
BSTSerialize(Root,ar) ;
}
else
{ // loading code
ar.Read (&Root , sizeof(Root)) ;
UnBSTSerialize(Root,ar) ;
}
}
void BSTSerialize(BinarySearchTreeNode *tempRoot ,CArchive& ar)
{
if(NULL==tempRoot)
return ;
if(Root != tempRoot)
{
ar.Write (&tempRoot , sizeof(tempRoot)) ;
if(tempRoot->InChild)
{
ar.Write (&tempRoot->InChild , sizeof(tempRoot->InChild)) ;
}
}
BSTSerialize(tempRoot->leftChild ,ar );
BSTSerialize(tempRoot->rightChild ,ar);
}
void UnBSTSerialize(BinarySearchTreeNode *tempRoot ,CArchive& ar)
{
if(NULL==tempRoot)
return ;
if(Root != tempRoot)
{
ar.Read (&tempRoot , sizeof(tempRoot)) ;
if(tempRoot->InChild)
{
ar.Read (&tempRoot->InChild , sizeof(tempRoot->InChild)) ;
}
}
UnBSTSerialize(tempRoot->leftChild ,ar );
UnBSTSerialize(tempRoot->rightChild ,ar);
}