iT邦幫忙

0

誰能幫忙改一下這程式

  • 分享至 

  • xImage

下面是我寫的程式碼
可是執行出來還是有2個小錯誤
題目是要求輸入例如I4 I6 I20 D6 I10(I是Intertion 而D是Deletion)
然後利用AVL tree來印出路徑

package datastructure;
import java.io.BufferedReader;

import java.io.InputStreamReader;

public class AVL
{
public static void main(String[] args)throws Exception
{
Tree tl = new Tree();
String choice = "y";

while (choice.equalsIgnoreCase("y"))
{
System.out.println("Enter Operation you need to perform ie I-Insert and D-Delete");
System.out.println("Example - I4 means insert 4 and D4 means Delete 4 from Avl Tree");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = br.readLine();

char opr = input.charAt(0);
int value = Integer.parseInt(input.substring(1, input.length()));

if(opr == 'I' || opr == 'i')
{
tl.insert(value);

}

if (opr == 'D' || opr == 'd')
{
tl.delete(value);
}
System.out.println("Tree looks like:"+tl);
System.out.println("Treedepth:"+tl.depth());
System.out.println("Want to continue(y/n)");
choice = br.readLine();
}
}
}

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

6
fillano
iT邦超人 1 級 ‧ 2010-12-29 09:24:01

我有預感這個問題會被刪除啦XD

不過...你的AVL Tree在哪裡?你只寫了個main...要問問題的話,至少先寫出AVL Tree,然後看看你的問題在哪裡吧?

6
bizpro
iT邦大師 1 級 ‧ 2010-12-29 09:58:52

把Tree砍了之後, 用String tl = ""; 取代, 程式是正常的.

大大說有兩個錯誤, 莫非指的就是Tree的宣告和初始化?
$ javac datastructure/AVL.java
datastructure/AVL.java:10: cannot find symbol
symbol : class Tree
location: class datastructure.AVL
Tree tl = new Tree();
^
datastructure/AVL.java:10: cannot find symbol
symbol : class Tree
location: class datastructure.AVL
Tree tl = new Tree();
^
2 errors

那肯定是六祖才能解決的:
菩提本無樹, 明鏡亦非台, 本來無一物, 何處惹塵埃?

我要發表回答

立即登入回答