online_judge_1503

#include 

using namespace std;

struct BiTNode
{
    int data;
    BiTNode *left;
    BiTNode *right;
};
int loc;
int n;

BiTNode* createTree()
{
    cin>>loc;
    if(loc == 0)
    {
        return NULL;
    }
    BiTNode *T = new BiTNode();
    T->data = loc;
    loc++;
    T->left = createTree();
    T->right = createTree();
    return T;
}

void delTree(BiTNode *T)
{
    if(T==NULL)
        return;
    delTree(T->right);
    delete T;
}

void Convert(BiTNode *curT, BiTNode **T)
{
    if(curT == NULL)
        return ;
    BiTNode *pcur = curT;
    if(pcur->left != NULL)
        Convert(pcur->left, T);
    pcur->left = *T;
    if((*T) != NULL)
        (*T)->right = pcur;
    *T = pcur;
    if(pcur->right!=NULL)
        Convert(pcur->right, T);
}

void printList(BiTNode *T)
{
    while(T)
    {
        cout<data<<" ";
        T = T->right;
    }
    cout<left != NULL)
        (*tt) = (*tt)->left;
}

int main()
{
    BiTNode *T = NULL;
    BiTNode *tt = NULL;
    cin>>n;
    while(n--)
    {
        T = NULL;
        tt = NULL;
        loc = 0;
        T = createTree();
        Convert(T, &tt);
        ReverseList(&tt);
        printList(tt);
        delTree(tt);
    }
    return 0;
}

 

是个好题目,但是在oj里很水。特别是输出太不符合OJ的强迫症了……

你可能感兴趣的:(Online,C++)