任何机构都可以为我将这个简单的代码更改为java? :( [英] can any body change this simple code to java for me? : (

查看:63
本文介绍了任何机构都可以为我将这个简单的代码更改为java? :(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的项目需要的代码
但是我不熟悉c ++
任何机构都可以将其更改为java plz?:(

here is code i need it for my project
but i am not familiar with c++
can any body change it to java plz?:(

void iterativePostOrder(Node* root) {
        if (!root) {
                return;
        }
        stack<node*> nodeStack;
 
        Node* cur = root;
        while (true) {
                if (cur) {
                        if (cur->right) {
                                nodeStack.push(cur->right);
                        }
                        nodeStack.push(cur);
                        cur = cur->left;
                        continue;
                }
 
                if (nodeStack.empty()) {
                        return;
                }
 
                cur = nodeStack.top(); 
                nodeStack.pop();
 
                if (cur->right && !nodeStack.empty() && cur->right == nodeStack.top()) {
                        nodeStack.pop();
                        nodeStack.push(cur);
                        cur = cur->right;
                } else {
                        std::cout << cur->val << " ";
                        cur = NULL;
                }
        }
}

推荐答案

private void iterativePostOrder(Node root)
{
		if (root == null)
		{
				return;
		}
		java.util.Stack<node> nodeStack = new java.util.Stack<node>();

		Node cur = root;
		while (true)
		{
				if (cur != null)
				{
						if (cur.right)
						{
								nodeStack.push(cur.right);
						}
						nodeStack.push(cur);
						cur = cur.left;
						continue;
				}

				if (nodeStack.empty())
				{
						return;
				}

				cur = nodeStack.peek();
				nodeStack.pop();

				if (cur.right && !nodeStack.empty() && cur.right == nodeStack.peek())
				{
						nodeStack.pop();
						nodeStack.push(cur);
						cur = cur.right;
				}
				else
				{
						System.out.print(cur.val);
						System.out.print(" ");
						cur = null;
				}
		}
}</node></node>



使用此演示转换器 [ ^ ]



Used this demo Converter[^]


当您连看都不懂的时候,怎么知道它有用呢?

Node *是一个指针.您可以在这里以与对待接口相同的方式对待它.

您可能还需要阅读以下内容:
XML教程@ oracle.com [ XML-API @ oracle.com上的示例
How do you know it''s useful when you can''t even read it?

the Node* is a pointer. You can treat it here in the same way you would treat an interface.

You also might want to read this:
Tutorial on XML @ oracle.com[^]
samples on XML-API @oracle.com


这篇关于任何机构都可以为我将这个简单的代码更改为java? :(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆