struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution {
public:
    bool isSymmetrical(TreeNode* pRoot) {
        if(!pRoot)
            return true;
        if(!pRoot->left&&!pRoot->right)
            return true;
        TreeNode* lroot=pRoot->left;
        TreeNode* rroot=pRoot->right;
        stack<TreeNode*>s1;
        stack<TreeNode*>s2;
        int f=0;
        while(lroot||!s1.empty()){
            f=1;
            while(lroot){
                if(!rroot)
                    return false;
                if(lroot->val!=rroot->val)
                    return false;
                s1.push(lroot);
                lroot=lroot->left;
                s2.push(rroot);
                rroot=rroot->right;
            }
            lroot=s1.top();
            s1.pop();
            lroot=lroot->right;
            rroot=s2.top();
            s2.pop();
            rroot=rroot->left;
        }
        if(f)
            return true;
        return false;
    }

};