緊急求救JAVA作業(一共有兩個檔案~因字數限制所以猜開)

Problem DescriptionYou are required to implement a custom generic Ordered List class to manipulate a list of compa-rable objects in an increasing oder at all time. The assignment includes two Java program files,OrderedList.java and OrderedListTest.java; and the prototypes of both files are given below. Pleasefill out the missing method implementation.The program of OrderedListTest.java is given as follows:public class OrderedListTest {

public static void main(String[] args) {OrderedList< Double > list = new OrderedList< Double >();for ( int i = 1; i <= 25; i++ ) {list.insert( Math.random() ); } list.print();try {

Double removeItem = list.removeMin();

System.out.printf( "\nThe minimal %s removed\n", removeItem );list.print();removeItem = list.removeMin();

System.out.printf( "\nThe minimal %s removed\n", removeItem );list.print();removeItem = list.removeMax();

System.out.printf( "\nThe maximal %s removed\n", removeItem );list.print();removeItem = list.removeMax();

System.out.printf( "\nThe maximal %s removed\n", removeItem );list.print();}

catch ( EmptyListException emptyListException ) {emptyListException.printStackTrace();}}}

Update:

第二個作業是連續的~但因為字數限制的關係!

請看此網址

http://tw.knowledge.yahoo.com/question/question?qi...

感激!

Update 2:

謝謝~非常感激你!!

不過我不太了解到底哪個是完整版的?哪裡開修飾以及怎麼修改之類的?

可以麻煩你給我完整版麻@?@

真的很感激你哦!!

1 Answer

Rating
  • 9 years ago
    Favorite Answer

    OrderedListTest.java就跟你的一模一樣...

    OrderedList.java

    http://codepad.org/S7lOhumD

    功能有出來,但寫的很爛,僅供參考orz

    2012-05-04 18:06:23 補充:

    沒仔細看第2題所以重寫...

    2012-05-04 21:14:06 補充:

    主要是要改OrderedList.java吧

    PO在這裡,參考看看吧

    http://codepad.org/3JNKlAav

    那個firstNode我漏看了...所以lastNode被我拿來當另外的用途

    放進去的值我並沒有做排序,只在removeMin()和removeMax()裡頭做手腳,其實兩個幾乎是一模一樣...

    2012-05-04 21:26:08 補充:

    改一下這兩個地方

    public T removeMin() {

    ListNode min = lastNode;

    ...

    }

    public T removeMax() {

    ListNode max = lastNode;

    ...

    }

    2012-05-05 08:08:05 補充:

    按照值的大小擺入list中,最小值為firstNode,最大值為lastNode

    http://codepad.org/8srgnIlu

    2012-05-05 10:38:21 補充:

    我只有改寫OrderedList.java缺的部份(它裡面含有ListNode,這個也是跟題目一模一樣)

    那兩個都可以用(OrderedList.java和OL.java),前面那個是照順序放,後面是照值的大小放...

    2012-05-05 10:38:45 補充:

    針對OL補上2個remove方法要丟出EmptyListException

    public T removeMin() {

    ListNode target = firstNode;

    if (target == null){

    throw new EmptyListException();

    }

    firstNode = target.getNext();

    return target.getData();

    }

    2012-05-05 10:39:02 補充:

    public T removeMax() {

    ListNode target = lastNode;

    if (target == null){

    throw new EmptyListException();

    }

    ...

    }

    2012-05-05 10:41:44 補充:

    OL.java完整碼

    http://codepad.org/qHQ7j8Ya

    2012-05-05 10:46:48 補充:

    那個insert的方法看不懂的話可以討論,有關泛型的部份就自行研究吧,我也是頭一回寫,也不太懂...

    Source(s): 自己
Still have questions? Get your answers by asking now.