Guest User

Untitled

a guest
Feb 20th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. class LinkList {
  2. private Node tmp;
  3. private int len;
  4.  
  5.  
  6. public LinkList(){
  7. len=0;
  8. tmp=null;
  9. }
  10.  
  11.  
  12. void add(int val){
  13. if(tmp==null){
  14. tmp=new Node(val, null,null);
  15. }
  16. else{
  17. while(tmp.r!=null) tmp=tmp.r;
  18. Node t = new Node(val,tmp,null);
  19. tmp.r=t;
  20.  
  21. }
  22. }
  23. public void show(){
  24. while(tmp.r!=null)tmp=tmp.r;
  25. while(tmp!=null){
  26. System.out.println(tmp.val+" ");
  27. tmp=tmp.l;
  28. }
  29. }
  30.  
  31. }
  32.  
  33. class Node{
  34. int val;
  35. Node l,r;
  36.  
  37. public Node(int val, Node l, Node r) {
  38. this.val = val;
  39. this.l = l;
  40. this.r = r;
  41. }
  42. }
  43. smartAdd
Add Comment
Please, Sign In to add comment