Advertisement
Guest User

Untitled

a guest
Aug 30th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. public class DoublyLinkedList {
  2. private class NodeDLL {
  3. int data;
  4. NodeDLL next = null;
  5. NodeDLL prev = null;
  6. public NodeDLL(int data){
  7. this.data = data;
  8. }
  9. }
  10.  
  11. NodeDLL head = null;
  12. NodeDLL tail = null;
  13.  
  14. public DoublyLinkedList(){this.head = null; this.tail = null;}
  15.  
  16. public void append(int data){
  17. if (head == null){
  18. head = new NodeDLL(data);
  19. tail = head;
  20. }
  21. else{
  22. tail.next = new NodeDLL(data);
  23. tail.next.prev = tail;
  24. tail = tail.next;
  25. }
  26. }
  27.  
  28. public void prepend(int data){
  29. if (head == null){
  30. head = new NodeDLL(data);
  31. tail = head;
  32. }
  33. else{
  34. head.prev = new NodeDLL(data);
  35. head.prev.next = head;
  36. head = head.prev;
  37. }
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement