title: Making a linked list where each node is connected to another linked list.(java)
body: <p>I am creating a program that will read in a file, organize all of the words in lexicographic order, and output the word, how many times it appears in the document, and on what lines it appears. I have implemented this code in four different class files. However, I am having trouble linking the words to the linked list that will show the line numbers that the linked list arrives in. I am supposed to use the nodes of front and rear to traverse the list and am unsure how to go about iterating through this list and printing out each word.</p>
  
  <p>here is the code form the class that take strings and make a linked list: </p>
  
  <pre><code>private class Node
          implements Entry&lt;String, IntQueue&gt; {
      String key;
      IntQueue queue = new IntQueue();
      Node link;
  
      Node(String keyword, Node newlink) {
          key = keyword;
          link = newlink;
      }
  
      public String getKey() {
          return key;
      }
  
      public IntQueue getValue() {
          return queue;
      }
  
      public IntQueue setValue(IntQueue queue) {
          throw new UnsupportedOperationException();
      }
  
  
  }
  
  private Node head = new Node("", null);
  
  public ListMap() {
      // Not needed, since head defaults to null anyway.
  }
  
  public void insert(String key, int linenr) {
      misc.trace("insert", key, linenr);
      Node prevcursor = head;
      Node cursor = head.link;
      boolean write = false;
      while (cursor != null) {
  
          if (key.compareTo(cursor.getKey()) &lt; 0) {
              prevcursor.link = new Node(key, prevcursor.link);
              prevcursor.link.getValue().insert(linenr);
              write = true;
              break;
          }
          if (key.compareTo(cursor.getKey()) == 0) {
              cursor.queue.insert(linenr);
              write = true;
              break;
          }
          prevcursor = prevcursor.link;
          cursor = cursor.link;
      }
      if (!write) {
          prevcursor.link = new Node(key, prevcursor.link);
          prevcursor.link.getValue().insert(linenr);
      }
  }
  </code></pre>
  
  <p>and here is the code that acually makes the int linked list: </p>
  
  <pre><code>  class IntQueue
              implements Iterable&lt;Integer&gt; {
  
          private class node {
              int linenr;
              node link;
  
              node(int number, node newlink) {
                  linenr = number;
                  link = newlink;
              }
          }
  
          private int count = 0;
          private node rear = null;
          private node front = new node(0, null);
          private int linenumb = 0;
  
         private int count = 0;
     private node rear = null;
     private node front = null;
     private int linenumb= 0;
  
  
  
       public void insert (int number) {
            ++count;
            misc.trace (count);
            if(front=null){
            node temp = new node(number,rear.link);
            front = temp;
            rear = temp;
            }else{
            if(linenumb != number ){
              rear.link= new node(number,null);
              }
            }
            linenumb = number;
            rear = rear.link;
         }
  </code></pre>
  
  <p>the big problem is the insert function in the second class. I can't understand how to link front and rear and to consistently add a new node every time the function is called in a way that can be called later</p>