/*
	判断BST
	BST特点:
		小于根节点值在根节点左侧
		大于根节点值在根节点右侧 
*/

#include <iostream>
#include <vector> 

using namespace std;

struct TreeNode
{
	int val;
	struct TreeNode *LeftNode;
	struct TreeNode *RightNode;
	
	TreeNode(int x):
	val(x),LeftNode(NULL),RightNode(NULL){}
};

class Checker
{
	vector<int>vt;
	public:
	/*
		利用中序遍历将节点数据记录下来 
	*/ 
	void search(TreeNode *root)
	{
		if(root!=NULL)
		{
			search(root->LeftNode);
			vt.push_back(root->val);
			search(root->RightNode);
		}	
	} 
	
	bool checkBST(TreeNode *root)
	{
		for(int i=0;i<vt.size()-1;i++)
		{
			if(vt[i]>vt[i+1])
			{
				return false;
			}
		}	
		return true;			
	}
}

int main(int argc, char *argv[])
{
	return 0;
}

  

相关文章:

  • 2022-12-23
  • 2021-05-21
  • 2021-10-02
  • 2022-12-23
  • 2022-02-04
  • 2022-12-23
  • 2021-12-07
猜你喜欢
  • 2022-12-23
  • 2021-10-26
  • 2021-12-28
  • 2021-10-24
  • 2022-12-23
  • 2022-12-23
  • 2021-05-16
相关资源
相似解决方案