在优先级队列中遇到节点问题

时间:2012-05-26 14:10:06

标签: java priority-queue

我遇到了这段代码的问题。为什么在失败之前只将一个节点放入Priority cue?

代码运行一次然后在循环中失败但是当我用相似的代码打印出来的时候它可以工作。但是当它进入prority线索时不会。

 package schduler;

 import java.io.*;
 import java.util.*;
 import java.math.*;

  // based on tutorial from http://youtu.be/3RNYUKxAgmw
  public class ReadFile {

public static Scanner processTree;



public static void openFile(String textString){

    try {

        processTree = new Scanner(new File(textString));
        System.out.println("the monkeys have found the file " + textString);
        readInfoFile();
        try 
        {
        //  readInfoFile();
        }
        catch (Exception e)
        {
            System.out.println("the monkeys couldn't read the file");
        }
    }
    catch (Exception e)
    {
        System.out.println("This file is NOT accessable from here. The monkeys have gotten lost!!!!!");
    }

}
   // this is the problem section
public static void readInfoFile(){
 int queStart = Integer.parseInt(processTree.next()); 

    while(processTree.hasNext()){

        LLNode thisNode = new LLNode();

        thisNode.processName = processTree.next();
        thisNode.priority = Integer.parseInt(processTree.next());
        LLNode.startTime = Integer.parseInt(processTree.next());
        System.out.println(thisNode.processName + " " + thisNode.priority + " " + thisNode.startTime);
        thisNode.next = null;

        main.processQue.add(thisNode);
        LLNode tempNode = new LLNode();
        tempNode = main.processQue.peek();
        System.out.println(tempNode.processName + " " + tempNode.priority + " " + tempNode.startTime);
    }
}
public void closeFile()
{
    processTree.close();
}

}`

这是主要的课程

package schduler;
import java.*;
import java.awt.List;
import java.util.PriorityQueue;

public class main {
public static PriorityQueue<LLNode> processQue = new PriorityQueue<LLNode>();

/**
 * @param args
 */
public static void main(String[] args) {

    // TODO Auto-generated method stub

    ReadFile.openFile(args[0]);

}

 }

0 个答案:

没有答案