TODO: Build an Linked List Data Structure with the following operations: data fields: The fields to declare have private You will keep track of the size of the list with the variable size and the start of the list with the reference variable data. ? first is a reference variable for the first Node in the list. ? last is a reference variable for the last Node in the list. ? size keeps track of the number of nodes in the list of type int. This will allow you to know the current size of the list without having to traversing the list. constructors: The overloaded constructors will initialize the data fields size and data. ? The first constructor is a default constructor initializes the starting node location “first” and size to a zero equivalent, that is, constructs an empty list. public LinkedList() ? The second constructor copies the contents of another list into the current list. public LinkedList(List other) methods: methods that manages the behavior of the linked nodes. ? add: appends elements to the end of the list. This method returns true, if the data was added successfully. public boolean add(E item) ? add: inserts elements at a given location in the list, shifting subsequent elements to the right. public void add(int index, E item) ? checkIndex: checks if the given index is valid. Throws an IndexOutOfBoundsException, if invalid. This is a private helper method. private void checkIndex(int index) ? clear: clears list of all elements, returns size back to zero. public void clear() ? contains: searches for a specific item within the linked structure and returns true, if the item is in the list. public boolean contains(E item) ? detach: detaches the node at the specified index from list.
#Sales Offer!| Get upto 25% Off: