Question & Answer: can someone help in adding a zero argument constructor that creates an empty list to my LinkedList below?…..

can someone help in adding a zero argument constructor that creates an empty list to my LinkedList below?

public class LinkedList extends ALinkedList {

// @override

public ALinkedList extract(int start, int end) {

LinkedList list = new LinkedList();

for (int i = start; i <= end; i++) {

Node current = head;

int count = 0;

while (++count <= i) {

head = head.getNext();

}

String t = head.get();

super.remove();

current.setNext(current.getNext());

size–;

list.add(t);

}

return list;

}

public static void main(String[] args) {

boolean LinkedList = false;

LinkedList linkedList2 = new LinkedList();

linkedList2.add(“1”);

linkedList2.add(“2”);

linkedList2.add(“3”);

linkedList2.add(“4”);

System.out.println(linkedList2.extract(1, 2));

}

}

Expert Answer

 

class Node

{

protected int data;

protected Node next;

public Node()

{

next = null;

data = 0;

}

public Node(int d,Node n)

{

data = d;

next = n;

}

public void setNext(Node list)

{

next = list;

}

public void set(int value)

{

data = value;

}

public Node getNext()

{

return next;

}

public int get()

{

return data;

}

}

public class LinkedList extends ALinkedList

{

public Node start;

public Node end ;

public int size ;

start = null;

end = null;

size = 0;

public LinkedList() //Zero Arguement Constructor

{

if(start==null)

{

next.next = null;

start = next;

end=next;

}

else

{

end.next=next;

next.next=null;

end=next;

}

}

public ALinkedList extract(int start, int end)

{

LinkedList list = new LinkedList();

for (int i = start; i <= end; i++)

{

Node current = head;

int count = 0;

while (++count <= i)

{

head = head.getNext();

}

String t = head.get();

super.remove();

current.setNext(current.getNext());

size–;

list.add(t);

}

return list;

}

public static void main(String[] args)

{

boolean LinkedList = false;

LinkedList linkedList2 = new LinkedList();

linkedList2.add(“1”);

linkedList2.add(“2”);

linkedList2.add(“3”);

linkedList2.add(“4”);

System.out.println(linkedList2.extract(1, 2));

}

}

Still stressed from student homework?
Get quality assistance from academic writers!