Guest User

Untitled

a guest
Jul 16th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. /*
  2. class Node
  3. {
  4.  
  5.     int val;
  6.     Node next;
  7.  
  8.     Node(int v, Node n)
  9.     {
  10.         val = v;
  11.         next = n;
  12.     }
  13. }
  14.  
  15. class LinkedList
  16. {
  17.     Node first;
  18.     Node last;
  19.     int count = 0;
  20.  
  21.     public void add(Node in)
  22.     {
  23.         if (count == 0)
  24.         {
  25.             first = in;
  26.             last = in;
  27.             count++;
  28.             return;
  29.         }
  30.         last.next = in;
  31.         last = in;
  32.         count++;
  33.     }
  34.  
  35.     public void sout()
  36.     {
  37.         Node buff = first;
  38.         while (buff != null)
  39.         {
  40.             System.out.print(buff.val + " ");
  41.             buff = buff.next;
  42.         }
  43.         System.out.println("");
  44.     }
  45. }
  46.  
  47. class Run
  48. {
  49.     public static void main(String[] args)
  50.     {
  51.         LinkedList test = new LinkedList();
  52.         test.add(new Node(1, null));
  53.         test.add(new Node(2, null));
  54.         test.add(new Node(3, null));
  55.         test.add(new Node(4, null));
  56.         test.add(new Node(5, null));
  57.         test.add(new Node(6, null));
  58.         test.add(new Node(5, null));
  59.         test.add(new Node(6, null));
  60.         test.sout();
  61.         Homework5.rl(test,6);
  62.         test.sout();
  63.         Homework5.rev(test);
  64.         test.sout();
  65.     }
  66. }*/
Add Comment
Please, Sign In to add comment