首页 > 其他 > 详细

二叉树有关知识

时间:2015-09-21 21:11:36      阅读:286      评论:0      收藏:0      [点我收藏+]

// ConsoleApplication11.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>

using namespace std;


typedef struct TreeNode
{
int data;
struct TreeNode * pLeft;
struct TreeNode * pRight;
}TreeNode;
typedef struct TreeNode* pTreeNode;

void InOrder(pTreeNode p); //中序遍历

 

int _tmain(int argc, _TCHAR* argv[])
{

TreeNode *pRoot = new TreeNode;

TreeNode *temp1 = new TreeNode;
TreeNode *temp2 = new TreeNode;

pRoot->data = 1;
pRoot->pLeft = NULL;
pRoot->pRight = NULL;

temp1->data = 2;
temp1->pLeft = NULL;
temp1->pRight = NULL;
temp2->data = 3;
temp2->pLeft = NULL;
temp2->pRight = NULL;
pRoot->pLeft = temp1;
pRoot->pRight = temp2;
InOrder(pRoot);
return 0;
}

void InOrder(pTreeNode p)
{
if (p == NULL)
return;

InOrder(p->pLeft);
cout << p->data;
InOrder(p->pRight);
}

 

二叉树有关知识

原文:http://www.cnblogs.com/wll-zju/p/4826973.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!