online_judge_1503

来源:互联网 发布:美国读研gpa算法 编辑:程序博客网 时间:2024/06/05 22:31
#include <iostream>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<<T->data<<" ";        T = T->right;    }    cout<<endl;}void ReverseList(BiTNode **tt){    while((*tt)->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的强迫症了……

0 0
原创粉丝点击