Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.    
  2. public class List1
  3. {
  4.     private class Node
  5.     {
  6.         private Node next;
  7.         private Node prev;
  8.         public Car c;
  9.        
  10.         public Node() //Basic ass node class
  11.         {
  12.             next = null;
  13.             prev = null;
  14.             c = null;          
  15.         }
  16.         public Node(Node next, Node prev, Car c) {
  17.  
  18.             this.next = next;
  19.             this.prev = prev;
  20.             this.c = c;
  21.         }
  22.        
  23.         public Node getNext() {
  24.             return next;
  25.         }
  26.  
  27.         public void setNext(Node next) {
  28.             this.next = next;
  29.         }
  30.  
  31.         public Node getPrev() {
  32.             return prev;
  33.         }
  34.  
  35.         public void setPrev(Node prev) {
  36.             this.prev = prev;
  37.         }
  38.  
  39.         public Car getC() {
  40.             return c;
  41.         }
  42.  
  43.         public void setC(Car c) {
  44.             this.c = c;
  45.         }
  46.     }
  47.    
  48.     private Node head;
  49.     private Node tail;
  50.     private int size;
  51.    
  52.     public List1()
  53.     {
  54.         head = null;
  55.         tail = null;
  56.         size = 0;
  57.     }
  58.    
  59.     public void AddtoIndex(int i, Car k)
  60.     {
  61.         if(i == 0)
  62.         {
  63.             Node NN = new Node(head, null, k);
  64.             head = NN;
  65.             size++;
  66.         }
  67.         else if(i>0 && i<size)
  68.         {
  69.             Node temp = head;
  70.             int f = 0;
  71.             while (f != i-1)
  72.             {
  73.                 temp = temp.next;
  74.                 f++;
  75.             }
  76.             Node NN = new Node(temp.next,temp,k);
  77.             temp.next.prev = NN;
  78.             temp.next = NN;
  79.             size++;
  80.         }
  81.         else if(i == size)
  82.         {
  83.             Node NN = new Node(null, tail, k);
  84.             tail = NN;
  85.             size++;
  86.         }
  87.        
  88.     }
  89.     public void ShowListContent()
  90.     {
  91.          Node temp = head;
  92.            for(int i = 0;i <size;i++)
  93.            {
  94.                System.out.println(temp.c);
  95.                temp = temp.next;
  96.            }
  97.     }
  98.    
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement