Complete LinkedListCollection.java with following methods:
public LinkedListCollection();
public LinkedListCollection(int size);
public boolean isEmpty();
public int size(); // Return number of elements in the Collection.
public String toString();
public boolean add(T element); // Add an element into the Collection, return true if successful
public boolean remove(T target); // Remove the target from Collection, return true if successful
public boolean removeAll(T target); // Remove all occurrences of Target, return if successful
public void removeDuplicate(); // Remove duplicated element(s)
public boolean equals(LinkedListCollection that); // Return true if this Collection is same as that Collection
public int count(T target); // Return the number of a given target in the Collection
public void merge(LinkedListCollection that); // Merge this Collection with that Collection
public void enlarge(int size); //Increase this Collection with additional size elements
public void clear(); // Clear entire Collection
public boolean contains(T target); // Return true if the target is in the Collection
package Homework3;
public class LinkedListCollection <T> {
protected Node<T> head = null;
public LinkedListCollection() {
}
public boolean isEmpty() {
return head == null;
}
public int size() {
int counter = 0;
Node<T> cursor = head;
while (cursor != null) {
cursor = cursor.getLink();
counter++;
}
return counter;
}
public String toString() {
Node<T> cursor = head;
String collection = "";
while (cursor != null) {
collection += cursor.getInfo() + "\n";
cursor = cursor.getLink();
}
return collection;
}
public boolean add(T element) {
// Insert at head
Node<T> node = new Node<T>(element);
// Code here
return true;
}
public boolean remove(T target) {
Node<T> cursor = head;
Node<T> previous = head;
while (cursor != null) {
// Code here
previous = cursor;
cursor = cursor.getLink();
}
return false;
}
public boolean removeAll(T target) {
Node<T> cursor = head;
Node<T> previous = head;
boolean found = false;
// Code here
return found;
}
public void removeDuplicate() {
// Remove any duplicated elements
// Code here
}
public boolean equals(LinkedListCollection that) {
// Return true if LinkedListCollection are identical.
boolean result = true;
Node<T> cursor_this = head;
Node<T> cursor_that = that.head;
while (cursor_this != null && cursor_that != null) {
if (!cursor_this.getInfo().equals(cursor_that.getInfo()))
result = false;
cursor_this = cursor_this.getLink();
cursor_that = cursor_that.getLink();
}
return result && this.size() == that.size();
}
public int count(T target) {
// Return count of target occurrences
int c = 0;
Node<T> cursor = head;
// Code here
return c;
}
public void merge(LinkedListCollection that) {
// Merge that LinkedListCollection into this LinkedListCollection
if (that.head == null) return; // Nothing to merge
if (this == that) return; // Same list
// Code here
}
public void clear() {
// Remove all elements in the collection
}
public boolean contains(T target) {
// Return true if target is found
boolean found = false;
Node<T> cursor = head;
// Code here
return found;
}
}
The following code have all the "Code here" filled.
public class LinkedListCollection <T> {
protected Node<T> head = null;
public LinkedListCollection() {
}
public boolean isEmpty() {
return head == null;
}
public int size() {
int counter = 0;
Node<T> cursor = head;
while (cursor != null) {
cursor = cursor.getLink();
counter++;
}
return counter;
}
public String toString() {
Node<T> cursor = head;
String collection = "";
while (cursor != null) {
collection += cursor.getInfo() + "\n";
cursor = cursor.getLink();
}
return collection;
}
public boolean add(T element) {
// Insert at head
Node<T> node = new Node<T>(element);
// Code here
//setting head as it's next element, now head is the second element
and node links to head
node.setLink(head);
//setting node as the new head, so that node is called wherever
head is neaded
head = node;
return true;
}
public boolean remove(T target) {
Node<T> cursor = head;
Node<T> previous = head;
while (cursor != null) {
// Code here
// if the current Node's Info is equal to Target,
//then we link previous Node to the next NOde, unlinking self from
the chain
if(cursor.getInfo() == target){
//Linking next Node to the previous
previous.setLink(cursor.getLink());
//returning true, returning stops the function
//so no need to worry about loop anymore
return true;
}
previous = cursor;
cursor = cursor.getLink();
}
return false;
}
public boolean removeAll(T target) {
Node<T> cursor = head;
Node<T> previous = head;
boolean found = false;
// Code here
//creating loop to traverse node by node till there is no next
node
while (cursor != null) {
// if the current Node's Info is equal to Target,
if(cursor.getInfo() == target){
//then we link previous Node to the next NOde, unlinking self from
the chain
previous.setLink(cursor.getLink());
//setting cursor to next node to traverse further
cursor = cursor.getLink();
//setting found to true
found = true;
//continue directly starts the next iteration of loop
//doing this because we already set the next no need to execute
further
continue;
}
//in case target does not match current nodes data
//then we set current node as previoous
//and set next nose as current
previous = cursor;
cursor = cursor.getLink();
}
return found;
}
public void removeDuplicate() {
// Remove any duplicated elements
// Code here
//Creating another Linked List that will not hold any duplicate
data
LinkedListCollection <T> other = new LinkedListCollection
<T>();
//setting this LL's cursor
Node<T> cursor_this = head;
//setting No duplicate LL's cursor
Node<T> cursor_other = head;
//Traversing through the LL with duplicate entries
while (cursor_this != null){
//if (LL with no duplicates) does not have the Info of current node
of (LL that have duplicate)
if(!other.contains(cursor_this.getInfo())){
//then we add this link to the LL with no Duplicates
cursor_other.setLink(cursor_this);
//updating cursor of No duplicate LL i.e, other
//so that we can further add to it whenever new non-duplicate node
appears
cursor_other= cursor_other.getLink();
}
//setting next node of duplicate as current node in
traversing
cursor_this = cursor_this.getLink();
}
}
public boolean equals(LinkedListCollection that) {
// Return true if LinkedListCollection are identical.
boolean result = true;
Node<T> cursor_this = head;
Node<T> cursor_that = that.head;
while (cursor_this != null && cursor_that != null) {
if (!cursor_this.getInfo().equals(cursor_that.getInfo()))
result = false;
cursor_this = cursor_this.getLink();
cursor_that = cursor_that.getLink();
}
return result && this.size() == that.size();
}
public int count(T target) {
// Return count of target occurrences
int c = 0;
Node<T> cursor = head;
// Code here
//traversing through the LL
while (cursor != null) {
//adding the count by 1 on every element tha is traversed
c++;
//setting next node as the current node
cursor = cursor.getLink();
}
return c;
}
public void merge(LinkedListCollection that) {
// Merge that LinkedListCollection into this LinkedListCollection
if (that.head == null) return; // Nothing to merge
if (this == that) return; // Same list
// Code here
//creating cursor to traverse through list
Node<T> cursor= this.head;
//running infinite loop
while (true) {
//if next node is null
//that means we have reached the last of 'this' LL
if(cursor.getLink() == null){
//linking the head of 'that' as the last node's next of
'this'
cursor.setLink(that.head);
//stoping the loop
break;
}
//setting next node as the current node
cursor = cursor.getLink();
}
}
public void clear() {
// Remove all elements in the collection
//code here
//setting head of the LL to null
//every LL starts from head, if head is null there is no LL
this.head = null;
}
public boolean contains(T target) {
// Return true if target is found
boolean found = false;
Node<T> cursor = head;
// Code here
//traversing every node of the LL
while (cursor != null) {
//matching the nodes info to target
if(cursor.getInfo() == target){
//detting found = true so that true is returned
found= true;
}
//setting next node as the current node
cursor = cursor.getLink();
}
return found;
}
}
This is the indentation:








Happy to help :)
Complete LinkedListCollection.java with following methods: public LinkedListCollection(); public LinkedListCollection(int size); public boolean isEmpty(); public int size();...
Complete LinkedListSet.java in java programming language. package Homework3; public class LinkedListSet extends LinkedListCollection { LinkedListSet() { } public boolean add(T element) { // Code here return true; } } Below is the LinkedListCollection.java code. Use to complete LinkedListSet.java. public class LinkedListCollection <T> { protected Node<T> head = null; public LinkedListCollection() { } public boolean isEmpty() { return head == null; } public int size() { int counter = 0; Node<T> cursor = head; while (cursor != null) { cursor =...
Question from Object-Oriented Data Structures Using Java 4th Edition Chapter 5 Question 30 Add the following methods to the LinkedCollection class, and create a test driver for each to show that they work correctly. Code each of these methods by accessing the internal variables of the LinkedCollection, not by calling the previously defined methods of the class.String toString() creates and returns a string that correctly represents the current collection. 1. Such a method could prove useful for testing and debugging...
Modify the LinkedCollection class to be a SortedLinkedCollecton class and see how that effects our implementation for adding and removing items. You should reference the SortedArrayCollection class provided for how these algorithms should be implemented. What needs to change here? Is it a lot of code or not much? Include a toString method that creates and returns a string that correctly represents the current collection. Include a test driver application that demonstrates your class correctly. //--------------------------------------------------------------------------- // LinkedCollection.java // //...
Java Programming: The following is my code: public class KWSingleLinkedList<E> { public void setSize(int size) { this.size = size; } /** Reference to list head. */ private Node<E> head = null; /** The number of items in the list */ private int size = 0; /** Add an item to the front of the list. @param item The item to be added */ public void addFirst(E...
could somone please help me to complete this ! public class MyLinkedList<AnyType> { private Node<AnyType> head, tail; private int size; public MyLinkedList() { this.head = null; this.tail = null; this.size = 0; } //1.Insert a node at the end of the list public void insert(AnyType data) { Node<AnyType> newNode = new Node(); newNode.data = data; if (head == null) { head = newNode; tail = newNode; head.next = null; tail.next = null; } else { tail.next = newNode; tail =...
Improve the speed of public T get(int i) by having it work backward from the end of the array if you attempt to get a member which is closer to the end than the start. This improvement will be tested through timing tests on large lists. The method should still return null if i is not a valid index. Code import java.util.Iterator; public class DLList<T> implements Iterable<T> { private static class Node<T> { public Node<T> prev, next;...
When compiling the LinkedList and Iterator class, the following error is being produced: Note: LinkedList.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. Any suggestions? public class LinkedList<T> { Node<T> itsFirstNode; Node<T> itsLastNode; private int size; public LinkedList() { itsFirstNode = null; itsLastNode = null; size = 0; } public Iterator<T> getIterator() { return new Iterator(this); } // THIS WILL NEED...
Java help: Please help complete the locate method that is in bold.. public class LinkedDoubleEndedList implements DoubleEndedList { private Node front; // first node in list private Node rear; // last node in list private int size; // number of elements in list ////////////////////////////////////////////////// // YOU MUST IMPLEMENT THE LOCATE METHOD BELOW // ////////////////////////////////////////////////// /** * Returns the position of the node containing the given value, where * the front node is at position zero and the rear node is...
Here is the IntegerLinkedList_incomplete
class:
public class IntegerLinkedList {
static class Node {
/** The element stored at this node */
private int element; // reference to the element stored at this node
/** A reference to the subsequent node in the list */
private Node next; // reference to the subsequent node in the list
/**
* Creates a node with the given element and next node.
*
* @param e the element to be stored
* @param n...
Plz help me with the code. And here are the requirement. Thanks!! You are required to design and implement a circular list using provided class and interface. Please filling the blank in CircularList.java. This circular list has a tail node which points to the end of the list and a number indicating how many elements in the list. And fill out the blank of the code below. public class CircularList<T> implements ListInterface<T> { protected CLNode<T> tail; // tail node that...