码迷,mamicode.com
首页 > 其他好文 > 详细

二叉树有关知识

时间:2015-09-21 21:12:03      阅读:124      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!