首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

能帮小弟我解决上这个bug吗

2012-12-24 
能帮我解决下这个bug吗IDE 提示:error: class PriorityQApp is public, should be declared in a file nam

能帮我解决下这个bug吗
IDE 提示:  error: class PriorityQApp is public, should be declared in a file named PriorityQApp.java public class PriorityQApp {  


可是我已经写了 public 了啊


////////////////////////////////////////////////////////////////  
class Link {  
    public long dData; // data item  
    public Link next; // next link in list  
  
    // -------------------------  
  
    public Link(long dd) // constructor  
    {  
        dData = dd;  
    }  
  
    // -------------------------  
    public void displayLink() // display this link  
    {  
        System.out.print(dData + " ");  
    }  
} // end class Link  
// //////////////////////////////////////////////////////////////  
  
class SortedList {  
  
    private Link first; // ref to first item  
  
    // -------------------------  
  
    public SortedList() // constructor  
    {  
        first = null;  
    }  
  
    // -------------------------  
    public boolean isEmpty() // true if no links  
    {  
        return (first == null);  
    }  
  
    // -------------------------  
    public void insert(long key) // insert, in order  
    {  
        Link newLink = new Link(key); // make new link  
        Link previous = null; // start at first  
        Link current = first;  
        // until end of list,  
        while (current != null && key > current.dData) { // or key > current,  
            previous = current;  
            current = current.next; // go to next item  
        }  


        if (previous == null) // at beginning of list  
            first = newLink; // first --> newLink  
        else  
            // not at beginning  
            previous.next = newLink; // old prev --> newLink  
        newLink.next = current; // newLink --> old currnt  
    } // end insert()  
        // -------------------------  
  
    public Link remove() // return & delete first link  
    { // (assumes non-empty list)  
        Link temp = first; // save first  
        first = first.next; // delete first  
        return temp; // return value  
    }  
  
    // -------------------------  
    public void displayList() {  
        System.out.print("List (first-->last): ");  
        Link current = first; // start at beginning of list  
        while (current != null) // until end of list,  
        {  
            current.displayLink(); // print data  
            current = current.next; // move to next link  
        }  
        System.out.println("");  
    }  
} // end class SortedList  
  
// //////////////////////////////////////////////////////////////  
// =================================================================  
// 编程作业 5.1  
class PriorityQ {  
    private SortedList sortedList;  
  
    public PriorityQ() {  
        sortedList = new SortedList();  
    }  
  
    public void insert(long item) {  
        sortedList.insert(item);  
    }  
  
    public long remove() {  
        return sortedList.remove().dData;  
    }  


  
    public boolean isEmpty() {  
        return sortedList.isEmpty();  
    }  
  
    public void display() {  
        sortedList.displayList();  
    }  
}  
  
// =================================================================  
public class PriorityQApp {  
    public static void main(String[] args) {  
        PriorityQ thePQ = new PriorityQ();  
        thePQ.insert(30);  
        thePQ.insert(50);  
        thePQ.insert(10);  
        thePQ.insert(40);  
        thePQ.insert(20);  
        thePQ.display();  
        while (!thePQ.isEmpty()) {  
            long item = thePQ.remove();  
            System.out.print(item + " "); // 10, 20, 30, 40, 50  
        } // end while  
        System.out.println("");  
    } // end main()  
}  
// =================================================================  
[解决办法]
你的java文件名要写成:PriorityQApp.java

热点排行