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.
它不起作用.
这是我的代码.我无法理解是什么问题,但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)