Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class List1
- {
- private class Node
- {
- private Node next;
- private Node prev;
- public Car c;
- public Node() //Basic ass node class
- {
- next = null;
- prev = null;
- c = null;
- }
- public Node(Node next, Node prev, Car c) {
- this.next = next;
- this.prev = prev;
- this.c = c;
- }
- public Node getNext() {
- return next;
- }
- public void setNext(Node next) {
- this.next = next;
- }
- public Node getPrev() {
- return prev;
- }
- public void setPrev(Node prev) {
- this.prev = prev;
- }
- public Car getC() {
- return c;
- }
- public void setC(Car c) {
- this.c = c;
- }
- }
- private Node head;
- private Node tail;
- private int size;
- public List1()
- {
- head = null;
- tail = null;
- size = 0;
- }
- public void AddtoIndex(int i, Car k)
- {
- if(i == 0)
- {
- Node NN = new Node(head, null, k);
- head = NN;
- size++;
- }
- else if(i>0 && i<size)
- {
- Node temp = head;
- int f = 0;
- while (f != i-1)
- {
- temp = temp.next;
- f++;
- }
- Node NN = new Node(temp.next,temp,k);
- temp.next.prev = NN;
- temp.next = NN;
- size++;
- }
- else if(i == size)
- {
- Node NN = new Node(null, tail, k);
- tail = NN;
- size++;
- }
- }
- public void ShowListContent()
- {
- Node temp = head;
- for(int i = 0;i <size;i++)
- {
- System.out.println(temp.c);
- temp = temp.next;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement