摘要:
问题判断一数字序列是否为这些数字入栈的一种出栈方式(前提:栈中的数字不重复)例如假设入栈的序列为:1 2 3 4 5那么4 5 3 2 1为一种弹出序列, 4 3 5 1 2不是思路开辟一个辅助栈,模拟入栈出战过程(假设pa为入栈序列,pb为出战序列)pa中的元素依次压入辅助栈新压入的元素与弹出序列的栈底相同,辅助栈弹出,同时pb向上移动不相同了pa中的元素继续入辅助栈参考代码#include #include using namespace std;bool IsPopOrder(const int *a, const int *b, int lena, int lenb){ if(l... 阅读全文
posted @ 2014-03-22 23:01
jihite
阅读(4229)
评论(0)
推荐(0)
摘要:
思路参考代码#include using namespace std;void printNumAsClockwise(int a[][4], int row, int col){ if (row = left; --i) cout = up; --i) cout using namespace std;void printNumAsClockwise(int *a, int row, int col){ if (row = left; --i) cout = up; --i) cout << ... 阅读全文
posted @ 2014-03-22 20:35
jihite
阅读(626)
评论(0)
推荐(0)
摘要:
镜像——照镜子得出的像。特征就是左右反着,如下图思路仿着递归遍历,递归得到镜像输入结点指针p不为空且部位叶子,反转p的左右孩子找p的左孩子的镜像找p的右孩子的镜像参考代码void getImage(BinaryTreeNode *root){ if(root != NULL && root->m_pLeft != NULL && root->m_pRight != NULL) { BinaryTreeNode *temp = root->m_pLeft; root->m_pLeft = root->m_pRight; root-&g 阅读全文
posted @ 2014-03-22 17:42
jihite
阅读(1139)
评论(0)
推荐(0)
摘要:
题目输入两颗二叉树A和B,判断B是否是A的子结构,例如下图中B是A的子结构 A B参考代码1bool IsPartTree(TreeNode *root1, TreeNode *root2){ if(root1 == NULL... 阅读全文
posted @ 2014-03-22 17:12
jihite
阅读(1185)
评论(2)
推荐(0)

浙公网安备 33010602011771号