简体   繁体   中英

Creating a node for a LinkedList in Java

I am trying to create a queue of nodes. Each node will have 2 values (m and n). Relatively new to Java and wanted to know how can I create/implement a queue of nodes in which each node has a set of 2 int values (m, n).

My approach would be as follows:

Node {
  DataType m;
  DataType n;
  Node next; // you use to connect to other nodes in the list
  //constructor{ }
}

Simple node list:

public class List{
   class Node{
      protected int a, b;
      Node next;

      public Node(int a, int b){
         this.a = a;
         this.b = b;
      }

      //some get methods 
   }

   Node root = null;

   public void insertNode(int a, int b){
      new_node = new Node(a, b);

      new_node.next = root;

      root = new_node; 
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM