从java转c_java 转为c

publicclassBinaryTree{/***Anodeofthebinarytreecontainingthenode'sintegervalue*andpointerstoitsrightandleftchildren(ornull).*/staticclassNode{intvalue;Nodeleft=null;Noderi...

public class BinaryTree {

/**

* A node of the binary tree containing the node's integer value

* and pointers to its right and left children (or null).

*/

static class Node {

int value;

Node left = null;

Node right = null;

/**

* Create a new node with no children.

*/

Node (int value) {

this.value = value;

}

/**

* Insert the node n into the binary tree rooted by this node.

*/

void insertNode (Node n) {

if (n.value <= value) {

if (left==null)

left = n;

else

left.insertNode (n);

} else {

if (right==null)

right = n;

else

right.insertNode (n);

}

}

/**

* Insert value into the binary tree rooted by this node, creating a new node for value.

*/

void insert (int value) {

Node n = new Node (value);

insertNode (n);

}

/**

* Print the contents entire binary tree in order of ascending integer value.

*/

void printInOrder() {

if (left != null)

left.printInOrder();

System.out.printf ("%d\n", value);

if (right != null)

right.printInOrder();

}

}

/**

* Create a node to root a new tree, populate it with a few values, and print it.

*/

public static void main (String[] args) {

Node root = new Node (100);

root.insert (10);

root.insert (120);

root.insert (130);

root.insert (90);

root.insert (5);

root.insert (95);

root.insert (121);

root.insert (131);

root.insert (1);

root.printInOrder();

}

}

谢谢 是一个BinaryTree。

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值