Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. package oct18;
  2.  
  3. public class TestProgram {
  4. public static void main(String[] args) {
  5. Node<Integer> inthead = new Node<Integer>(3, null);
  6. Node<Integer> inttail = inthead;
  7. inthead = new Node<Integer>(2, inthead);
  8. inthead = new Node<Integer>(1, inthead);
  9. inttail.next = inthead;
  10.  
  11. Node<Integer> noderef = inthead;
  12. do {
  13. System.out.println(noderef.data);
  14. noderef = noderef.next;
  15. } while (noderef != inthead);
  16.  
  17. Node<String> stringhead = new Node<String>("Cher", null);
  18. Node<String> stringtail = stringhead;
  19. stringhead = new Node<String>("Bob", stringhead);
  20. stringhead = new Node<String>("Alice", stringhead);
  21. stringtail.next = stringhead;
  22.  
  23. Node<String> stringref = stringhead;
  24. for (int j = 0; j < 2; j++) {
  25. for (int i = 0; i < 3; i++) {
  26. System.out.println(stringref.data);
  27. stringref = stringref.next;
  28. }
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement