Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Node<T>
- {
- private T info;
- private Node<T> next;
- public Node(T x)
- {
- this.info = x;
- this.next = null;
- }
- public Node(T x, Node<T> next)
- {
- this.info = x;
- this.next = next;
- }
- public Node<T> getNext()
- {
- return this.next;
- }
- public void setNext(Node<T> next)
- {
- this.next = next;
- }
- public T getInfo()
- {
- return this.info;
- }
- public void setInfo(T x)
- {
- this.info = x;
- }
- public String toString()
- {
- return this.info.toString();
- }
- public void printChain() {
- System.out.println("The chain is:");
- Node<T> pos=this;
- while (pos!=null) {
- if (pos.getNext()==null) System.out.print(pos);
- else System.out.print(pos+" -->");
- pos=pos.getNext();
- }
- System.out.println();
- }
- }
Add Comment
Please, Sign In to add comment