小编Tur*_*dov的帖子

如何递归地找到二叉树中节点的高度

path = 0 # the lenght of the path
    while self.right != None or self.left != None:
        while self.right != None:
            self = self.right
            path = path +1 
        while self.left != None:
            self = self.left
            path = path +1
    return path
Run Code Online (Sandbox Code Playgroud)

这是我查找高度的示例代码,定义为从自身到叶子的节点数量的最长路径的长度.叶节点的高度为1.

它不起作用.

python algorithm binary-tree

5
推荐指数
3
解决办法
2万
查看次数

运算符(*)不能应用于'object'和'double'类型的操作数

这是我的代码.我无法理解是什么问题,但Visual Studio 2008说

运算符(*)不能应用于'object'和'double'类型的操作数

谢谢 ...

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace DailyRate
{
    class Program
    {
        static void Main(string[] args)
        {
            (new Program()).run();
        }

        public void run()
        {
            double dailyRate = readDouble("Enter your daily rate: ");
            int noOfDays = readInt("Enter the number of days: ");
            writeFree(CalculateFee(dailyRate, noOfDays));
        }

        private void writeFree(object p)
        {
            Console.WriteLine("The consultant's fee is: {0}", p * 1.1);
        }

        private double CalculateFee(double dailyRate, int noOfDays)
        {
            return dailyRate * noOfDays;
        } …
Run Code Online (Sandbox Code Playgroud)

c#

-3
推荐指数
1
解决办法
3477
查看次数

标签 统计

algorithm ×1

binary-tree ×1

c# ×1

python ×1