How do I fix it in LinkedList.java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementExcept.
LabProgram.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition <>
* @return the value stored at node first
* @throws NoSuchElementException <>
*/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
/**
* Returns the value stored in the last node
* @precondition <>
* @return the value stored in the node last
* @throws NoSuchElementException <>
*/
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return iterator.data;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition <>
*/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition <>
*/
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIter.
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
How do I fix it in LinkedList.java?
LabProgram.java
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoS.
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
How do I fix it in LinkedList.java?
this is what i did
LabProgram.java
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void remov.
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdffacevenky
Copy your completed LinkedList class from Lab 3 into the LinkedList.java file below.
During this lab we will add more constructors, an equals method and more challenging methods
as listed below.
Also inspect the LabProgram.java file and notice that the main() method of the LabProgram
copies and compares two linked lists. The main() method also calls the more challenging
methods. Use Develop mode to test your LinkedList iterator code as you develop it.
In Submit mode you will need to complete all lab steps to pass all automatic tests.
Step 2: Implement clear()
Method clear() re-sets the LinkedList to empty as if the default constructor had just been called.
Constructor LinkedList(T[] array) converts the given array into a LinkedList.
Constructor LinkedList(LinkedList original) instantiates a new LinkedList by copying another
List.
Method equals() determines whether the given Object is another LinkedList, containing the same
data in the same order, returning whether there is equality.
Method spinList(int numMoves) moves all nodes in the list towards the end of the list the
number of times specified. Any node that falls off the end of the list as it moves forward will be
placed at the front of the list.
Method altLists() splices together two LinkedLists to create a third List which contains
alternating values from the original list and the given parameter.
*Below is my Lab3 LinkedList.class.
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
public T getFirst() throws NoSuchElementException {
if (first == null) throw new NoSuchElementException();
return first.data;
}
public T getLast() throws NoSuchElementException {
if (last == null) throw new NoSuchElementException();
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator == null) {
throw new NullPointerException("Iterator is off end.");
}
return iterator.data;
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
Node newNode = new Node(data);
if (length == 0) {
first = newNode;
last = newNode;
} else .
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
Here is the editable code:
Solution
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
public int size() { return size; }
public boolean isEmpty() { return size == 0; }
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* adds element at the end of the linked list
* @param element
*/
public void addLast(E element) {
Node tmp = new Node(element, null, tail);
if(tail != null) {tail.next = tmp;}
tail = tmp;
if(head == null) { head = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
public void iterateForward(){
System.out.println(\"iterating forward..\");
Node tmp = head;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.next;
}
}
/**
* this method walks backward through the linked list
*/
public void iterateBackward(){
System.out.println(\"iterating backword..\");
Node tmp = tail;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.prev;
}
}
public E removeFirst() {
if (size == 0) throw new NoSuchElementException();
Node tmp = head;
head = head.next;
head.prev = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public E removeLast() {
if (size == 0) throw new NoSuchElementException();
Node tmp = tail;
tail = tail.prev;
tail.next = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public static void main(String a[]){
DoublyLinkedListImpl dll = new DoublyLinkedListImpl();
dll.addFirst(10);
dll.addFirst(34);
dll.addLast(56);
dll.addLast(364);
dll.iterateForward();
dll.removeFirst();
dll.removeLast();
dll.iterateBackward();
}
}
import java.util.Scanner;
/* Class Node */
class Node
{
protected int data;
protected Node next, prev;
/* Constructor */
public Node()
{
next = null;
prev = null;
data = 0;
}
/* Constructor */
public Node(int d, Node n, Node p)
{
data = d;
next = n;
prev = p;
}
/* Function to set link to next node */
public void setLinkNext(Node n)
{
next = n;
}
/* Function to set link to previous node */
public void setLinkPrev(Node p)
{
prev = p;
}
/* Funtion to get link to next node */
public Node getLinkNext()
{
return next;
}
/* Function to get link to previous node */
public Node getLinkPrev()
{
return prev;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Class linkedList */
class linkedList
{
protected Node start;
protected Node end ;
public int size;
/* Constructor */
public linkedList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isE.
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
PROBLEM STATEMENT:
In this assignment, you will complete DoubleEndedList.java that implements the ListInterface as
well as an interface called DoubleEndedInterface which represents the list's entries by using a
chain of nodes that has both a head reference and a tail reference. Be sure to read through the
code and understand the implementation.
WHAT IS PROVIDED:
- A driver class to test your code. You should not modify this file!
- A list interface (ListInterface.java)
- A double ended interface (DoubleEndedInterface.java)
- An incomplete DoubleEndedList class (DoubleEndedList.java)
WHAT YOU NEED TO DO:
4. Complete the DoubleEndedList class
4. Run the driver and make sure your output is exactly the same as mine (at the bottom of
Driver.java)
\} // end else numberofEntries--; else throw new IndexOut0fBoundsException("Illegal position
given to remove operation."); return result; // Return removed entry }//endreturnreve public T
replace(int givenPosition, T newEntry) \{ T replace(int givenPosition, T newEntry) \{ if
((givenPosition >=1)&& (givenPosition <= numberOfEntries)) \{ // Assertion: The list is not
empty Node desiredNode = getNodeAt (givenPosition); ToriginalEntry = desiredNode.getData();
desiredNode.setData(newEntry); return originalEntry; f // end if else throw new
IndexOut0fBoundsException("Illegal position given to replace operation."); replace if ((
givenPosition >=1)&& (givenPosition <= number0fEntries)) \{ // Assertion: The list is not
empty Node desiredNode = getNodeAt ( givenPosition); T originalEntry = desiredNode.
getData( ); desiredNode.setData(newEntry); return originalentry; \} // end if throw new
Index0ut0fBoundsException("Illegal position given to replace operation."); \} // end replace
public T getEntry(int givenPosition) \{ if ((givenPosition >=1) \&\& (givenPosition < =
number0fEntries ) ) \{ // Assertion: The list is not empty return getNodeAt (givenPosition).
getData(); else // end if throw new IndexOut0fBoundsException("Illegal position given to
getEntry operation."); \} // end getEntry public boolean contains ( T anEntry) \{ boolean found =
false; Node currentNode = firstNode; while (!found && (currentNode != null)) \{ if
(anEntry.equals (currentNode.getData())) else found = true; \} // end while currentNode =
currentNode. getNextNode () ; return found; \} // end contains public int getLength() \{ return
numberofEntries; \} // end getLength public boolean isEmpty() \{ return number0fEntries ==0;
\} // end isEmpty public T[] toArray() \{ // The cast is safe because the new array contains null
entries aSuppressWarnings ("unchecked") T[] result =(T[]) new 0bject [numberofEntries]; //
Unchecked cast int index =0; Node currentNode = firstNode; while ((index < numberOfEntries)
\&\& (currentNode != null)) \& result [ index ]= currentNode. getData () ; currentNode =
currentNode.getNextNode ( ); index++; 3 // end while return result; 3 // end toArray // Returns a
reference to the node at a given position. // Precondition: L.
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfarkmuzikllc
I keep getting NullPointerExcepetion, can someone help me with spinList(int numMoves) and
LinkedList altLists(LinkedList list)?
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
public LinkedList() {
first = null;
last = null;
length = 0;
iterator = null;
}
public LinkedList(T[] array) {
if (array == null) {
return;
}
if (array.length == 0) {
length = 0;
first = null;
last = null;
iterator = null;
} else {
for (T item : array) {
addLast(item);
}
iterator = null;
}
}
public LinkedList(LinkedList original) {
if (original == null) {
return;
}
if (original.length == 0) {
length = 0;
first = null;
last = null;
iterator = null;
} else {
Node temp = original.first;
while (temp != null) {
addLast(temp.data);
temp = temp.next;
}
iterator = null;
}
}
public T getFirst() throws NoSuchElementException {
if(first == null){
throw new NoSuchElementException("getFirst(): List has no element to access");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (last == null){
throw new NoSuchElementException("getLast(): List has no element to access");
}
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator == null){
throw new NullPointerException("getIterator(): There is no iterator to access");
}
return iterator.data;
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
if (length == 0){
first = last = new Node(data);
} else {
Node fill = new Node(data);
fill.next = first;
first.prev = fill;
first = fill;
}
length++;
}
public void addLast(T data) {
if (length == 0) {
first = last = new Node(data);
} else {
Node fill = new Node (data);
fill.prev = last;
last.next = fill;
last = fill;
}
length++;
}
public void addIterator(T data) throws NullPointerException{
if(iterator == null) {
throw new NullPointerException("addIterator(): Can't add the node because iterator points
to null");
} else if(iterator == last){
addLast(data);
} else{
Node fill = new Node(data);
iterator.next.prev = fill;
fill.prev = iterator;
fill.next = iterator.next;
iterator.next = fill;
length++;
}
}
public void removeFirst() throws NoSuchElementException {
if (length == 0) {
throw new NoSuchElementException("removeFirst(): Cannot remove from an empty
List");
} else if(length == 1) {
first = last = null;
} else {
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if (length == 0){
throw new NoSuchElementException("removeLast(): Cannot remove from an empty
List");
} else if (length == 1){
first = last = null;
}else{
last = last.prev;
last.next = null;
}
length--;
}
public void removeIterator() throws NullPointerE.
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
/**
The LinkedList1 class implements a Linked list.
*/
class LinkedList1
{
/**
The Node class stores a list element
and a reference to the next node.
*/
private class Node
{
String value;
Node next;
/**
Constructor.
@param val The element to store in the node.
@param n The reference to the successor node.
*/
Node(String val, Node n)
{
value = val;
next = n;
}
/**
Constructor.
@param val The element to store in the node.
*/
Node(String val)
{
// Call the other (sister) constructor.
this(val, null);
}
}
private Node first; // list head
private Node last; // last element in list
/**
Constructor.
*/
public LinkedList1()
{
first = null;
last = null;
}
/**
The isEmpty method checks to see
if the list is empty.
@return true if list is empty,
false otherwise.
*/
public boolean isEmpty()
{
return first == null;
}
/**
The size method returns the length of the list.
@return The number of elements in the list.
*/
public int size()
{
int count = 0;
Node p = first;
while (p != null)
{
// There is an element at p
count ++;
p = p.next;
}
return count;
}
/**
The add method adds an element to
the end of the list.
@param e The value to add to the
end of the list.
*/
public void add(String e)
{
if (isEmpty())
{
first = new Node(e);
last = first;
}
else
{
// Add to end of existing list
last.next = new Node(e);
last = last.next;
}
}
/**
The add method adds an element at a position.
@param e The element to add to the list.
@param index The position at which to add
the element.
@exception IndexOutOfBoundsException When
index is out of bounds.
*/
public void add(int index, String e)
{
if (index < 0 || index > size())
{
String message = String.valueOf(index);
throw new IndexOutOfBoundsException(message);
}
// Index is at least 0
if (index == 0)
{
// New element goes at beginning
first = new Node(e, first);
if (last == null)
last = first;
return;
}
// Set a reference pred to point to the node that
// will be the predecessor of the new node
Node pred = first;
for (int k = 1; k <= index - 1; k++)
{
pred = pred.next;
}
// Splice in a node containing the new element
pred.next = new Node(e, pred.next);
// Is there a new last element ?
if (pred.next.next == null)
last = pred.next;
}
/**
The toString method computes the string
representation of the list.
@return The string form of the list.
*/
public String toString()
{
StringBuilder strBuilder = new StringBuilder();
// Use p to walk down the linked list
Node p = first;
while (p != null)
{
strBuilder.append(p.value + \"\ \");
p = p.next;
}
return strBuilder.toString();
}
/**
The remove method removes the element at an index.
@param index The index of the element to remove.
@return The element removed.
@exception IndexOutOfBoundsException When index is
out of bounds.
*/
public String remove(int index)
{
if (index < 0 || index >= size())
{
String message = String.valueOf(index);
throw new IndexOutOfBoundsException(message);
}
String element; // The element to return
if (index == 0)
{
// Removal of first item in the list
element.
LabProgram.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition <>
* @return the value stored at node first
* @throws NoSuchElementException <>
*/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
/**
* Returns the value stored in the last node
* @precondition <>
* @return the value stored in the node last
* @throws NoSuchElementException <>
*/
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return iterator.data;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition <>
*/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition <>
*/
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIter.
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfmail931892
How do I fix it in LinkedList.java?
LabProgram.java
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoS.
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfmail931892
How do I fix it in LinkedList.java?
this is what i did
LabProgram.java
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void remov.
Copy your completed LinkedList class from Lab 3 into the LinkedList..pdffacevenky
Copy your completed LinkedList class from Lab 3 into the LinkedList.java file below.
During this lab we will add more constructors, an equals method and more challenging methods
as listed below.
Also inspect the LabProgram.java file and notice that the main() method of the LabProgram
copies and compares two linked lists. The main() method also calls the more challenging
methods. Use Develop mode to test your LinkedList iterator code as you develop it.
In Submit mode you will need to complete all lab steps to pass all automatic tests.
Step 2: Implement clear()
Method clear() re-sets the LinkedList to empty as if the default constructor had just been called.
Constructor LinkedList(T[] array) converts the given array into a LinkedList.
Constructor LinkedList(LinkedList original) instantiates a new LinkedList by copying another
List.
Method equals() determines whether the given Object is another LinkedList, containing the same
data in the same order, returning whether there is equality.
Method spinList(int numMoves) moves all nodes in the list towards the end of the list the
number of times specified. Any node that falls off the end of the list as it moves forward will be
placed at the front of the list.
Method altLists() splices together two LinkedLists to create a third List which contains
alternating values from the original list and the given parameter.
*Below is my Lab3 LinkedList.class.
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
public T getFirst() throws NoSuchElementException {
if (first == null) throw new NoSuchElementException();
return first.data;
}
public T getLast() throws NoSuchElementException {
if (last == null) throw new NoSuchElementException();
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator == null) {
throw new NullPointerException("Iterator is off end.");
}
return iterator.data;
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
Node newNode = new Node(data);
if (length == 0) {
first = newNode;
last = newNode;
} else .
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfarrowmobile
Here is the editable code:
Solution
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
public int size() { return size; }
public boolean isEmpty() { return size == 0; }
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* adds element at the end of the linked list
* @param element
*/
public void addLast(E element) {
Node tmp = new Node(element, null, tail);
if(tail != null) {tail.next = tmp;}
tail = tmp;
if(head == null) { head = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
public void iterateForward(){
System.out.println(\"iterating forward..\");
Node tmp = head;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.next;
}
}
/**
* this method walks backward through the linked list
*/
public void iterateBackward(){
System.out.println(\"iterating backword..\");
Node tmp = tail;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.prev;
}
}
public E removeFirst() {
if (size == 0) throw new NoSuchElementException();
Node tmp = head;
head = head.next;
head.prev = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public E removeLast() {
if (size == 0) throw new NoSuchElementException();
Node tmp = tail;
tail = tail.prev;
tail.next = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public static void main(String a[]){
DoublyLinkedListImpl dll = new DoublyLinkedListImpl();
dll.addFirst(10);
dll.addFirst(34);
dll.addLast(56);
dll.addLast(364);
dll.iterateForward();
dll.removeFirst();
dll.removeLast();
dll.iterateBackward();
}
}
import java.util.Scanner;
/* Class Node */
class Node
{
protected int data;
protected Node next, prev;
/* Constructor */
public Node()
{
next = null;
prev = null;
data = 0;
}
/* Constructor */
public Node(int d, Node n, Node p)
{
data = d;
next = n;
prev = p;
}
/* Function to set link to next node */
public void setLinkNext(Node n)
{
next = n;
}
/* Function to set link to previous node */
public void setLinkPrev(Node p)
{
prev = p;
}
/* Funtion to get link to next node */
public Node getLinkNext()
{
return next;
}
/* Function to get link to previous node */
public Node getLinkPrev()
{
return prev;
}
/* Function to set data to node */
public void setData(int d)
{
data = d;
}
/* Function to get data from node */
public int getData()
{
return data;
}
}
/* Class linkedList */
class linkedList
{
protected Node start;
protected Node end ;
public int size;
/* Constructor */
public linkedList()
{
start = null;
end = null;
size = 0;
}
/* Function to check if list is empty */
public boolean isE.
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfclimatecontrolsv
PROBLEM STATEMENT:
In this assignment, you will complete DoubleEndedList.java that implements the ListInterface as
well as an interface called DoubleEndedInterface which represents the list's entries by using a
chain of nodes that has both a head reference and a tail reference. Be sure to read through the
code and understand the implementation.
WHAT IS PROVIDED:
- A driver class to test your code. You should not modify this file!
- A list interface (ListInterface.java)
- A double ended interface (DoubleEndedInterface.java)
- An incomplete DoubleEndedList class (DoubleEndedList.java)
WHAT YOU NEED TO DO:
4. Complete the DoubleEndedList class
4. Run the driver and make sure your output is exactly the same as mine (at the bottom of
Driver.java)
\} // end else numberofEntries--; else throw new IndexOut0fBoundsException("Illegal position
given to remove operation."); return result; // Return removed entry }//endreturnreve public T
replace(int givenPosition, T newEntry) \{ T replace(int givenPosition, T newEntry) \{ if
((givenPosition >=1)&& (givenPosition <= numberOfEntries)) \{ // Assertion: The list is not
empty Node desiredNode = getNodeAt (givenPosition); ToriginalEntry = desiredNode.getData();
desiredNode.setData(newEntry); return originalEntry; f // end if else throw new
IndexOut0fBoundsException("Illegal position given to replace operation."); replace if ((
givenPosition >=1)&& (givenPosition <= number0fEntries)) \{ // Assertion: The list is not
empty Node desiredNode = getNodeAt ( givenPosition); T originalEntry = desiredNode.
getData( ); desiredNode.setData(newEntry); return originalentry; \} // end if throw new
Index0ut0fBoundsException("Illegal position given to replace operation."); \} // end replace
public T getEntry(int givenPosition) \{ if ((givenPosition >=1) \&\& (givenPosition < =
number0fEntries ) ) \{ // Assertion: The list is not empty return getNodeAt (givenPosition).
getData(); else // end if throw new IndexOut0fBoundsException("Illegal position given to
getEntry operation."); \} // end getEntry public boolean contains ( T anEntry) \{ boolean found =
false; Node currentNode = firstNode; while (!found && (currentNode != null)) \{ if
(anEntry.equals (currentNode.getData())) else found = true; \} // end while currentNode =
currentNode. getNextNode () ; return found; \} // end contains public int getLength() \{ return
numberofEntries; \} // end getLength public boolean isEmpty() \{ return number0fEntries ==0;
\} // end isEmpty public T[] toArray() \{ // The cast is safe because the new array contains null
entries aSuppressWarnings ("unchecked") T[] result =(T[]) new 0bject [numberofEntries]; //
Unchecked cast int index =0; Node currentNode = firstNode; while ((index < numberOfEntries)
\&\& (currentNode != null)) \& result [ index ]= currentNode. getData () ; currentNode =
currentNode.getNextNode ( ); index++; 3 // end while return result; 3 // end toArray // Returns a
reference to the node at a given position. // Precondition: L.
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfarkmuzikllc
I keep getting NullPointerExcepetion, can someone help me with spinList(int numMoves) and
LinkedList altLists(LinkedList list)?
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
public LinkedList() {
first = null;
last = null;
length = 0;
iterator = null;
}
public LinkedList(T[] array) {
if (array == null) {
return;
}
if (array.length == 0) {
length = 0;
first = null;
last = null;
iterator = null;
} else {
for (T item : array) {
addLast(item);
}
iterator = null;
}
}
public LinkedList(LinkedList original) {
if (original == null) {
return;
}
if (original.length == 0) {
length = 0;
first = null;
last = null;
iterator = null;
} else {
Node temp = original.first;
while (temp != null) {
addLast(temp.data);
temp = temp.next;
}
iterator = null;
}
}
public T getFirst() throws NoSuchElementException {
if(first == null){
throw new NoSuchElementException("getFirst(): List has no element to access");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (last == null){
throw new NoSuchElementException("getLast(): List has no element to access");
}
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator == null){
throw new NullPointerException("getIterator(): There is no iterator to access");
}
return iterator.data;
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
if (length == 0){
first = last = new Node(data);
} else {
Node fill = new Node(data);
fill.next = first;
first.prev = fill;
first = fill;
}
length++;
}
public void addLast(T data) {
if (length == 0) {
first = last = new Node(data);
} else {
Node fill = new Node (data);
fill.prev = last;
last.next = fill;
last = fill;
}
length++;
}
public void addIterator(T data) throws NullPointerException{
if(iterator == null) {
throw new NullPointerException("addIterator(): Can't add the node because iterator points
to null");
} else if(iterator == last){
addLast(data);
} else{
Node fill = new Node(data);
iterator.next.prev = fill;
fill.prev = iterator;
fill.next = iterator.next;
iterator.next = fill;
length++;
}
}
public void removeFirst() throws NoSuchElementException {
if (length == 0) {
throw new NoSuchElementException("removeFirst(): Cannot remove from an empty
List");
} else if(length == 1) {
first = last = null;
} else {
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if (length == 0){
throw new NoSuchElementException("removeLast(): Cannot remove from an empty
List");
} else if (length == 1){
first = last = null;
}else{
last = last.prev;
last.next = null;
}
length--;
}
public void removeIterator() throws NullPointerE.
The LinkedList1 class implements a Linked list. class.pdfmalavshah9013
/**
The LinkedList1 class implements a Linked list.
*/
class LinkedList1
{
/**
The Node class stores a list element
and a reference to the next node.
*/
private class Node
{
String value;
Node next;
/**
Constructor.
@param val The element to store in the node.
@param n The reference to the successor node.
*/
Node(String val, Node n)
{
value = val;
next = n;
}
/**
Constructor.
@param val The element to store in the node.
*/
Node(String val)
{
// Call the other (sister) constructor.
this(val, null);
}
}
private Node first; // list head
private Node last; // last element in list
/**
Constructor.
*/
public LinkedList1()
{
first = null;
last = null;
}
/**
The isEmpty method checks to see
if the list is empty.
@return true if list is empty,
false otherwise.
*/
public boolean isEmpty()
{
return first == null;
}
/**
The size method returns the length of the list.
@return The number of elements in the list.
*/
public int size()
{
int count = 0;
Node p = first;
while (p != null)
{
// There is an element at p
count ++;
p = p.next;
}
return count;
}
/**
The add method adds an element to
the end of the list.
@param e The value to add to the
end of the list.
*/
public void add(String e)
{
if (isEmpty())
{
first = new Node(e);
last = first;
}
else
{
// Add to end of existing list
last.next = new Node(e);
last = last.next;
}
}
/**
The add method adds an element at a position.
@param e The element to add to the list.
@param index The position at which to add
the element.
@exception IndexOutOfBoundsException When
index is out of bounds.
*/
public void add(int index, String e)
{
if (index < 0 || index > size())
{
String message = String.valueOf(index);
throw new IndexOutOfBoundsException(message);
}
// Index is at least 0
if (index == 0)
{
// New element goes at beginning
first = new Node(e, first);
if (last == null)
last = first;
return;
}
// Set a reference pred to point to the node that
// will be the predecessor of the new node
Node pred = first;
for (int k = 1; k <= index - 1; k++)
{
pred = pred.next;
}
// Splice in a node containing the new element
pred.next = new Node(e, pred.next);
// Is there a new last element ?
if (pred.next.next == null)
last = pred.next;
}
/**
The toString method computes the string
representation of the list.
@return The string form of the list.
*/
public String toString()
{
StringBuilder strBuilder = new StringBuilder();
// Use p to walk down the linked list
Node p = first;
while (p != null)
{
strBuilder.append(p.value + \"\ \");
p = p.next;
}
return strBuilder.toString();
}
/**
The remove method removes the element at an index.
@param index The index of the element to remove.
@return The element removed.
@exception IndexOutOfBoundsException When index is
out of bounds.
*/
public String remove(int index)
{
if (index < 0 || index >= size())
{
String message = String.valueOf(index);
throw new IndexOutOfBoundsException(message);
}
String element; // The element to return
if (index == 0)
{
// Removal of first item in the list
element.
For this micro assignment, you must implement two Linked List functi.docxmckellarhastings
For this micro assignment, you must implement two Linked List functions. We will use the following
example Linked List:
2 0 -1 5 7
getElementAt(index)
This function should return the element (i.e. value) of the Nth item inside the linked list. For example,
on the Linked List above, getElementAt(0) should return 2; getElementAt(3) should return 5.
addElementAt(value, location)
This function should insert a new value at the given location. Note that the location supplied must be
within bounds of the LinkedList. For example, we cannot call addElementAt(4, 11) on the above Linked
List because 11 is beyond the size of the Linked List.
Here are some examples. If we call addElementAt(0, 1), the above Linked List would now look like:
1 2 0 -1 5 7
If we again call addElementAt(2, 123), we would get:
1 2 123 0 -1 5 7
Grading
Your submission will be graded based on the following:
1. [7] Your solution does not cause any runtime issues and your file passes all test cases
2. [3] Your code contains good style. For example,
You provide meaningful variable names
You provide sufficient and meaningful comments
Your code is well structured
@@@@@@@@@@@@@@@@@@@@@@@@
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include
#include
#include "LinkedListNode.h"
#include
using namespace std;
template
class LinkedList
{
private:
//points to the front of the linked list
LinkedListNode *_front = nullptr;
//keeping track of size in a variable eliminates need to continually
//count LL boxes.
int _size = 0;
protected:
//creates a new LinkedListNode for us
virtual LinkedListNode *createNode(T value)
{
return new LinkedListNode < T > { value };
}
public:
//default constructor
LinkedList()
{
_front = nullptr;
}
//copy constructor
LinkedList(const LinkedList &other)
{
for (int i = 0; i < other.getSize(); i++)
{
addElement(other.getElementAt(i));
}
}
//move constructor
LinkedList(LinkedList &&other)
{
//take other's data
_front = other._front;
_size = other._size;
//reset other's pointers
other._front = nullptr;
}
//initializer list constructor
LinkedList(initializer_list values)
{
for (auto item : values)
{
addElement(item);
}
}
//Always remember to clean up pointers in destructor!
virtual ~LinkedList()
{
LinkedListNode *current = _front;
while (current != nullptr)
{
LinkedListNode *temp = current->getNext();
delete current;
current = temp;
}
}
//will return true if the LL is empty.
virtual bool isEmpty() const
{
return _size == 0;
}
//returns the size of the LL.
virtual int getSize() const
{
return _size;
}
.
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition
* @return the value stored at node first
* @throws NoSuchElementException
*/
public T getFirst() throws NoSuchElementException {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
tested on eclipseDoublyLinkedList class.pdfshanki7
//tested on eclipse
/*************DoublyLinkedList class*******************/
public class DoublyLinkedList {
/*Data member variable declaration*/
private Node head;
private int count;
/**default constructor*/
public DoublyLinkedList() {
/*Initializing variable*/
head=null;
count =0;
}
/*Insert at beginning in doubly linked list*/
public void insertBeginning(String name){
/*checking head is null then we will add node at head*/
if(head==null){
head=new Node(name, null, null);
count++;
}else{
/*else create temp node and setting next to head
* and then making temp to head*/
Node temp=new Node(name,null,null);
temp.setNext(head);
head.setPrev(temp);
head=temp;
count++;
}
}
public void printList(){
Node temp=head;
/*Printing element of doubly list*/
while(temp!=null){
System.out.println(temp.getData());
temp=temp.getNext();
}
}
/*Returning count from doubly linked list*/
public int count(){
return count;
}
/*deleting specific node from doubly linked list*/
public void delete(String name){
Node current=head,previous=head;
/*if it is head node to be deleted*/
if(head.getData().equals(name)){
current=head.getNext();
current.setPrev(null);
head=current;
previous=head;
}else{
/*If node in middle of list*/
while(current.getNext()!=null){
if(current.getData().equals(name)){
current.getNext().setPrev(previous);
previous.setNext(current.getNext());
count--;
break;
}
previous=current;
current=current.getNext();
}
/*If node is at last*/
if(current.getNext()==null){
if(current.getData().equals(name)){
previous.setNext(null);
count--;
}
}
}
}
/*deleting all nodes from list by assigning head to null
* and memory releasing take care by garbage collector*/
public void clear(){
head=null;
count=0;
}
/*Inserting element in alphabetic order*/
public void insertAlpha(String name){
Node current=head,previous=head;
/*creating new node*/
Node newNode=new Node(name,null,null);
/*if head node is null*/
if(head==null){
head=newNode;
count++;
}else{
/*please read about compareTo() method about returning value*/
if(head.getData().compareTo(name)>0){
newNode.setNext(head);
head=newNode;
count++;
}else{
/*condition for getting position of node to be inserted*/
while(current!=null&¤t.getData().compareTo(name)<=0){
previous=current;
current=current.getNext();
}
/*if node need to be inserted at last*/
if(current==null){
previous=newNode;
}else{
/*If node need to inserted in middle*/
newNode.setNext(current);
previous.setNext(newNode);
current.setPrev(newNode);
newNode.setPrev(previous);
}
count++;
}
}
}
/*Main method start*/
public static void main(String args[]){
/*creating object of doubly linked list*/
DoublyLinkedList doublyLinkedList=new DoublyLinkedList();
doublyLinkedList.insertBeginning(\"sunita\");
doublyLinkedList.insertBeginning(\"lalchand\");
/*calling alphabetic order method*/
doublyLinkedList.insertAlpha(\"ramsingh\");
doublyLinkedList.insertBeginning(\"Lokesh\");
doublyLinkedList.insertBeginning(\"Pritam\");
/*****printing list********/
doublyLinkedList.printL.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
Complete in Java
CardApp.java
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public void shuffle() {
}
/**
* Implements the bubble sort algorithm
* to sort cardList into sorted order, first by suit
* (alphabetical order)
* then by rank from 2 to A
*/
public void sort() {
}
/**
* Returns the deck of cards with each card separated
* by a blank space and a new line character at the end.
* @return The deck of cards as a string.
*/
@Override public String toString() {
return "";
}
}
Card.java
public class Card implements Comparable{
private String rank;
private String suit;
/**
* Constructor for the Card class
* @param rank the rank of card from 2 to A
* @param suit the suit of card C, D, H, or S
*/
public Card(String rank, String suit) {
}
/**
* Returns the card's rank
* @return rank a rank from 2 (low) to A (high)
*/
public String getRank() {
return "";
}
/**
* Returns the card's suit
* @return C, D, H, or S
*/
public String getSuit() {
return "";
}
/**
* Updates the card's rank
* @param rank a new rank
*/
public void setRank(String rank) {
}
/**
* Updates the card's suit
* @param suit the new suit
*/
public void setSuit(String suit) {
}
/**
* Concatenates rank and suit
* @return card rank and suit
*/
@Override public String toString() {
return "";
}
/**
* Overrides the equals method for Card
* Compares rank and suit and
* follows the equals formula given in
* Lesson 4 and also in Joshua Block's text
* @param obj another Object to compare for
* equality
* @return whether obj is a Card and, if so,
* of equal rank and suit
*/
@Override public boolean equals(Object obj) {
return false;
}
/**
* Orders two cards first by suit (alphabetically)
* Next by rank. "A" is considered the high card
* Order goes 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
* @param card another Card to compare to this Card
* @return a negative number if this comes before c
* and a positive number if c comes before this
* and 0 if this and c are equal according to the above
* equals method
*/
@Override public int compareTo(Card card) {
return -1;
}
}
}
LinkedList.Java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterato.
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
Please help me to make a programming project I have to sue them today. Please help me make a
UnsortedList and SortedList classes. The instructor give me The code of the List and AbstracList
Classes that 2 pages we do not modify them. Do not modify this pages!!! List.java import
java.util.Iterator; /** * Represents List interface. * * @author Varik Hoang * @version Sep 26,
2016 * @param is of any object type. */ public interface List { /** * The method returns the
current number of elements in the list. * * @return the current number of elements in the list
greater than or equal 0 */ public int getSize(); /** * The method returns whether the list is empty.
* * @return true if list is empty, false otherwise. */ public boolean isEmpty(); /** * The method
returns whether value is in the list. * * @param value the value is assigned * @return true if
value in the list, false otherwise. */ public boolean contains(Type value); /** * The method
inserts an element into the list. * * @param value the value is assigned */ public void insert(Type
value); /** * The method clears the list. */ public void clear(); /** * The method returns a string
representation of list contents. * * @return a string representation of list contents. * @see
Object#toString() */ @Override public String toString(); /** * /** * The method removes first
element occurrence from the list. * * @param value the value is assigned * @return the removed
value */ public Type remove(Type value); /** * The method returns the index of value. * *
@param value the value is assigned. * @return the index of value if in the list, -1 otherwise. */
public int getIndex(Type value); /** * The method removes value at the given index. * *
@param index the index must be in range of 0 and size * @return the removed value * @throws
IndexOutOfBoundsException if index less than 0 or index greater than * or equal size */ public
Type removeAtIndex(int index); /** * The method replaces the value at the given index with the
given value. * * @param index the index must be in range of 0 and size * @param value the
value is assigned * @throws IndexOutOfBoundsException if index less 0 or index greater than
size */ public void set(int index, Type value); /** * Returns the value at the given index in the
list. * * @param index the index must be in range of 0 and size * @throws
IndexOutOfBoundsException if index less than 0 or greater size * @return the value at the given
index in the list. */ public Type get(int index); /** * The method returns an iterator for this list. *
* @return an iterator for the list. */ public Iterator iterator(); } Do not modify this pages public
abstract class AbstractList implements List { /** * The reference to the last element */ protected
ListNode tail; /** * The size of the list */ protected int size; /** * The constructor that initiate the
tail and size references */ public AbstractList() { tail = null; size = 0; } @Override public int
getSize() { return size; } @Override public bool.
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
Exception to indicate that Singly LinkedList is empty. .pdfaravlitraders2012
/**
* Exception to indicate that Singly LinkedList is empty.
*/
class LinkedListEmptyException extends RuntimeException {
public LinkedListEmptyException() {
super();
}
public LinkedListEmptyException(String message) {
super(message);
}
}
/**
* Node class, which holds data and contains next which points to next Node.
*/
class Node {
public int data; // data in Node.
public Node next; // points to next Node in list.
/**
* Constructor
*/
public Node(int data) {
this.data = data;
}
/**
* Display Node\'s data
*/
public void displayNode() {
System.out.print(data + \" \");
}
}
/**
* Singly LinkedList class
*/
class LinkedList {
private Node first; // ref to first link on list
/**
* LinkedList constructor
*/
public LinkedList() {
first = null;
}
/**
* Insert New Node at first position
*/
public void insertFirst(int data) {
Node newNode = new Node(data); // Creation of New Node.
newNode.next = first; // newLink ---> old first
first = newNode; // first ---> newNode
}
/**
* Method deletes specific Node from Singly LinkedList in java.
*/
public Node deleteSpecificNode(int deleteKey) {
// Case1: when there is no element in LinkedList
if (first == null) { // means LinkedList in empty, throw exception.
throw new LinkedListEmptyException(
\"LinkedList doesn\'t contain any Nodes.\");
}
// Case2: when there is only one element in LinkedList- check whether we
// have to delete that Node or not.
if (first.data == deleteKey) { // means LinkedList consists of only one
// element, delete that.
Node tempNode = first; // save reference to first Node in tempNode-
// so that we could return saved reference.
first = first.next;
System.out.println(\"Node with data=\" + tempNode.data
+ \" was found on first and has been deleted.\");
return tempNode; // return deleted Node.
}
// Case3: when there are atLeast two elements in LinkedList
Node previous = null;
Node current = first;
while (current != null) {
if (current.data == deleteKey) {
System.out.println(\"Node with data=\" + current.data
+ \" has been deleted.\");
previous.next = current.next; // make previous node\'s next point
// to current node\'s next.
return current; // return deleted Node.
} else {
if (current.next == null) { // Means Node wasn\'t found.
System.out.println(\"Node with data=\" + deleteKey
+ \" wasn\'t found for deletion.\");
return null;
}
previous = current;
current = current.next; // move to next node.
}
}
return null;
}
/**
* Display Singly LinkedList
*/
public void displayLinkedList() {
System.out.print(\"Displaying LinkedList [first--->last]: \");
Node tempDisplay = first; // start at the beginning of linkedList
while (tempDisplay != null) { // Executes until we don\'t find end of
// list.
tempDisplay.displayNode();
tempDisplay = tempDisplay.next; // move to next Node
System.out.print(\"-->\");
}
System.out.println();
}
}
/**
* Main class - To test LinkedList.
*/
public class SinglyLinkedListDeleteNodeExample {
public static void main(String[] args) {
LinkedList linkedList = new LinkedList(); /.
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
package singlylinkedlist;
public class Node {
public String value;
public Node next;
public Node(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
SingleyLinkedList.java :
package singlylinkedlist;
import java.io.*;
import java.util.*;
/**
* Defines the interface for a singly-linked list.
*
*/
public interface SinglyLinkedList {
/**
* @return Reference to the first node. If the list is empty, this method
* returns null.
*/
public Node getFirst();
/**
* @return Reference to the last node . If the list is empty, this method
* returns null.
*/
public Node getLast();
/**
* @return Number of nodes in the list
*/
public int size();
/**
* @return true if the list has no nodes; false otherwise
*/
public boolean isEmpty();
/**
* Removes all nodes in the list.
*/
public void clear();
/**
* Inserts a new node with the given value after cursor.
*
* @param cursor
* The node to insert after. Set this to null to insert value as
the
* new first Node.
* @param value
* The value to insert
* @return a reference to the newly inserted Node
*/
public Node insert(Node cursor, String value);
/**
* Inserts a new node with the given value at the "end" of the list.
*
* @param value
* @return a reference to the newly inserted Node
*/
public Node append(String value);
/**
* Removes the node after the specified Node (cursor) from the list.
*
* @param cursor
* A reference to the Node to remove.
*/
public void removeAfter(Node cursor);
/**
* Returns a reference to the first Node containing the key, starting from
the
* given Node.
*
* @param start
* @param key
* @return a reference to the first Node containing the key
*/
public Node find(Node start, String key);
/**
* Prints the values of all the items in a list
*/
public void printWholeList();
}
SinglyLinkedTester.java:
package sbccunittest;
import static java.lang.Math.*;
import static java.lang.System.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.junit.Assert.*;
import static sbcc.Core.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.junit.*;
import org.w3c.dom.ranges.*;
import sbcc.*;
import singlylinkedlist.*;
/**
* 09/16/2021
*
* @author sstrenn
*
*/
public class SinglyLinkedListTester {
public static String newline = System.getProperty("line.separator");
public static int totalScore = 0;
public static int extraCredit = 0;
public static boolean isZeroScore = false;
public static String scorePreamble = "";
@BeforeClass
public static void beforeTesting() {
totalScore = 0;
extraCredit = 0;
}
@AfterClass
public static void afterTesting() {
if (isZeroScore) {
totalScore = 0;
extraCredit = 0;
}
println(scorePreamble + "Estimated score (w/o late penalties, etc.) is:
" + totalScore + " out of 25.");
// If the project follows the naming convention, save the results in a
folder on
// the desktop. (Alex Kohanim)
try {
String directory =
substri.
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
Need Help!! C++
#include<iostream>
#include"linkedlist.h"
using namespace std;
/**
* @brief Destructor to destroy all nodes and release memory
*/
LinkedList::~LinkedList() {
//TODO: Add code here. Make sure memory is released properly.
}
/**
* @brief Purpose: Checks if the list is empty
* @return true if the list is empty, false otherwise
*/
bool LinkedList::isEmpty() const {
// TODO: Add code here
return count == 0;
}
/**
* @brief Get the number of nodes in the list
* @return int The number of nodes in the list
*/
int LinkedList::length() const{
//TODO: Add code here
}
/**
* @brief Convert the list to a string
*
*/
string LinkedList::toString() {
string str = "[";
Node *ptr = front;
if (ptr != nullptr) {
// Head node is not preceded by separator
str += to_string(ptr->val);
ptr = ptr->next;
}
while (ptr != nullptr) {
str += ", " + to_string(ptr->val);
ptr = ptr->next;
}
str += "]";
return str;
}
/**
* @brief Displays the contents of the list
*/
void LinkedList::displayAll() {
cout << toString() << endl;
}
//TODO: Add comments
void LinkedList::addRear(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
void LinkedList::addFront(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
bool LinkedList::deleteFront(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
//TODO: Add comments
bool LinkedList::deleteRear(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
/* --- harder ones for test 2 and 3 -- */
/**
* @brief Delete a node at a given position from the list. The
* node at position pos is deleted and the value of the deleted node is returned in val.
* The valid range of pos is 1 to count. pos = 1 is the first node, and pos = count is the last node.
* @param pos: position of the node to be deleted
* @param val: it is set to the value of the node to be deleted
* @return true: if the node was deleted successfully
* @return false: if the node was not deleted successfully because the position was out of range
*/
bool LinkedList::deleteAt(int pos, T &val) {
//TODO: Add code here
// check if the pos is valid first, then move the ptr to the rigth positon
// consider the special case of deleting the first node and the last node
// Do not forget to set value.
}
/**
* @brief Insert a value at a specified position in the list. The valid pos is in the range of 1 to
count+1.
* The value will be inserted before the node at the specified position. if pos = 1, the value will be
inserted
* at the front of the list. if pos = count+1, the value will be inserted at the rear of the list.
* @param pos: position to insert the value at.
* @param val: value to insert.
* @return true: if the value was inserte.
In this lab, we will write an application to store a deck of cards i.pdfcontact41
In this lab, we will write an application to store a deck of cards in a linked list, and then write
methods to sort and shuffle the deck.
Copy your completed LinkedList class from Lab 4 into the LinkedList.java file below.
Complete all methods of the Card class as described by the Javadoc comments. The class
contains both a suit and a rank. A suit is one of the categories into which the cards of a deck are
divided. The rank is the relative importance of the card within its suit.
Note that the Card constructor must convert any rank and suit letters to uppercase.
For the equals() method, be sure to follow the steps outlined in Lesson 4. How to implement the
compareTo() method is also covered in Lesson 4.
Note that you are not allowed to add any additional methods or member variables to this class or
you will not receive credit for this assignment.
Complete all methods of the CardApp class in the CardApp.java file as described by the Javadoc
comments.
You may add as many methods as you would like to this file, but are not allowed to add any
additional member variables.
The CardApp program must prompt for and allow the user to enter the name of any input file as
shown in the Example output below.
Implement the shuffle() method as specified in the comments for shuffle(). After you have
shuffled the deck of cards, write the result into a file named shuffled.txt.
Implement the sort() method using bubble sort from Lesson 4. First sort by suit in alphabetical
order and then by rank from 2 to A. The pseudocode for bubble sort is as follows:
After you have sorted the deck of cards, write the result to a file named sorted.txt.
The CardApp.java file also contains the main() method of the application. Use Develop mode to
test your CardApp code along with your Card and LinkedList code.
All input and output files must contain a list of cards, with each card stored on its own line. See
the example files cards1.txt and cards2.txt for example file formats.
[[[cards1.txt]]]
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
[[[cards2.txt]]]
AS
2S
3S
4S
5S
6S
7S
8S
9S
10S
JS
QS
KS
AC
2C
3C
4C
5C
6C
7C
8C
9C
10C
JC
QC
KC
AH
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
QH
KH
AD
2D
3D
4D
5D
6D
7D
8D
9D
10D
JD
QD
KD
[[[CardApp.java]]]
/**
* CardApp.java
* @author Your name
* @author Partner's name
* CIS 22C, Applied Lab 1
*/
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public vo.
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdfChristopherkUzHunter
public class CircularDoublyLinkedList<E> implements List<E> {
private class Node {
private E value;
private Node next, prev;
public Node(E value, Node next, Node prev) {
this.value = value;
this.next = next;
this.prev = prev;
}
public Node(E value) {
this(value, null, null); // Delegate to other constructor
}
public Node() {
this(null, null, null); // Delegate to other constructor
}
public E getValue() {
return value;
}
public void setValue(E value) {
this.value = value;
}
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 void clear() {
value = null;
next = prev = null;
}
} // End of Node class
private class ListIterator implements Iterator<E> {
private Node nextNode;
public ListIterator() {
nextNode = header.getNext();
}
@Override
public boolean hasNext() {
return nextNode != trailer;
}
@Override
public E next() {
if (hasNext()) {
E val = nextNode.getValue();
nextNode = nextNode.getNext();
return val;
}
else
throw new NoSuchElementException();
}
} // End of ListIterator class, DO NOT REMOVE, TEST WILL FAIL
/* private fields */
private Node header, trailer; // "dummy" nodes
private int currentSize;
public CircularDoublyLinkedList() {
/**
* Set dummy nodes to point to each other
*
* --> header <--> trailer <--
* | |
* __________________________
*
*/
header = new Node();
trailer = new Node(null, header, header);
header.setNext(trailer);
header.setPrev(trailer);
currentSize = 0;
}
@Override
public void add(E obj) {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public void add(E elm, int index) {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public boolean remove(E obj) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public boolean remove(int index) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public int removeAll(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public E get(int index) {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public E set(int index, E newElement) {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public int firstIndexOf(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public int lastIndexOf(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public E first() {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public E last() {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public int size() {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public boolean isEmpty() {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public boolean contains(E obj) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public void clear() {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public Iterator<E> iterator() {
return new ListIterator();
} //DO NOT DELETE, TESTS WILL FAIL
}
(Fill all TODO)
3. (20 pts) Head over to CircularDoublyLinkedList. java after finishing exercise 2. The
instructions for this exercis are as follows: - A circulardoublyl.
package com.java2novice.ds.linkedlist;
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
/**
* this class keeps track of each element information
* @author java2novice
*
*/
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
/**
* returns the size of the linked list
* @return
*/
public int size() { return size; }
/**
* return whether the list is empty or not
* @return
*/
public boolean isEmpty() { return size == 0; }
/**
* adds element at the starting of the linked list
* @param element
*/
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* adds element at the end of the linked list
* @param element
*/
public void addLast(E element) {
Node tmp = new Node(element, null, tail);
if(tail != null) {tail.next = tmp;}
tail = tmp;
if(head == null) { head = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* this method walks forward through the linked list
*/
public void iterateForward(){
System.out.println(\"iterating forward..\");
Node tmp = head;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.next;
}
}
/**
* this method walks backward through the linked list
*/
public void iterateBackward(){
System.out.println(\"iterating backword..\");
Node tmp = tail;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.prev;
}
}
/**
* this method removes element from the start of the linked list
* @return
*/
public E removeFirst() {
if (size == 0) throw new NoSuchElementException();
Node tmp = head;
head = head.next;
head.prev = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
/**
* this method removes element from the end of the linked list
* @return
*/
public E removeLast() {
if (size == 0) throw new NoSuchElementException();
Node tmp = tail;
tail = tail.prev;
tail.next = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public static void main(String a[]){
DoublyLinkedListImpl dll = new DoublyLinkedListImpl();
dll.addFirst(10);
dll.addFirst(34);
dll.addLast(56);
dll.addLast(364);
dll.iterateForward();
dll.removeFirst();
dll.removeLast();
dll.iterateBackward();
}
}
Solution
package com.java2novice.ds.linkedlist;
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
/**
* this class keeps track of each element information
* @author java2novice
*
*/
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
/**
* returns the size of the l.
Labprogram.java
LinkedList.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
*
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
*
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
public T getFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator != null) {
return iterator.data;
} else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
public void addIterator(T data) throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("addIterator Iterator is off end.");
}
if (iterator == last) {
addLast(data);
} else {
Node newNode = new Node(data);
Node next = iterator.next;
newNode.next = next;
newNode.prev = iterator;
iterator.next = newNode;
next.prev = newNode;
length++;
}
}
public void removeFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == first) {
iterator = null;
}
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == last) {
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
}
public void removeIterator() throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("Iterator is off the end opf the list.");
}
if (iterator .
public class MyLinkedListltE extends ComparableltEgtg.pdfaccostinternational
public class MyLinkedList<E extends Comparable<E>> {
private Node<E> head, tail;
private int size = 0; // Number of elements in the list
public MyLinkedList() {
head=tail=null;
size=0;
}
/** Return the head element in the list */
public E getFirst() {
if (size == 0) {
return null;
}
else {
return head.element;
}
}
/** Return the last element in the list */
public E getLast() {
if (size == 0) {
return null;
}
else {
return tail.element;
}
}
/** Add an element to the beginning of the list */
public void addFirst(E e) {
Node<E> newNode = new Node<>(e); // Create a new node
newNode.next = head; // link the new node with the head
head = newNode; // head points to the new node
size++; // Increase list size
if (tail == null) // the new node is the only node in list
tail = head;
}
/** Add an element to the end of the list */
public void addLast(E e) {
Node<E> newNode = new Node<>(e); // Create a new for element e
if (tail == null) {
head = tail = newNode; // The new node is the only node in list
}
else {
tail.next = newNode; // Link the new with the last node
tail = newNode; // tail now points to the last node
}
size++; // Increase size
}
public void add(int index, E e) {
if (index == 0) {
addFirst(e);
}
else if (index >= size) {
addLast(e);
}
else {
Node<E> current = head;
for (int i = 1; i < index; i++) {
current = current.next;
}
Node<E> temp = current.next;
current.next = new Node<>(e);
(current.next).next = temp;
size++;
}
}
//Add e to the end of this linkedlist
public void add(E e) {
// Left as Exercise
}
/** Remove the head node and
* return the object that is contained in the removed node. */
public E removeFirst() {
if (size == 0) {
return null;
}
else {
E temp = head.element;
head = head.next;
size--;
if (head == null) {
tail = null;
}
return temp;
}
}
/** Remove the last node and
* return the object that is contained in the removed node. */
public E removeLast() {
if (size == 0) {
return null;
}
else if (size == 1) {
E temp = head.element;
head = tail = null;
size = 0;
return temp;
}
else {
Node<E> current = head;
for (int i = 0; i < size - 2; i++) {
current = current.next;
}
E temp = tail.element;
tail = current;
tail.next = null;
size--;
return temp;
}
}
/** Remove the element at the specified position in this
* list. Return the element that was removed from the list. */
public E remove(int index) {
if (index < 0 || index >= size) {
return null;
}
else if (index == 0) {
return removeFirst();
}
else if (index == size - 1) {
return removeLast();
}
else {
Node<E> previous = head;
for (int i = 1; i < index; i++) {
previous = previous.next;
}
Node<E> current = previous.next;
previous.next = current.next;
size--;
return current.element;
}
}
/** Clear the list */
public void clear() {
size = 0;
head = tail = null;
}
/** Override toString() to return elements in the list in [] separated by , */
public String toString() {
StringBuilder result = new StringBuilder("[");
Node<E> current = head;
for (int i = 0; i < size; i++) {
result.append(current..
Consider a double-linked linked list implementation with the followin.pdfsales98
Consider a double-linked linked list implementation with the following node: struct Node {int
data; Node *prev; Node *next;} Write a copyList method that is not a member of any class.
The method should take a head pointer and return another pointer. Do not modify the input.
Solution
struct Node {
Node *prev; // previous node
Node *next; // next node
int data; // stored value
};
#include
#include \"List.h\" // std: #include
using namespace std;
typedef DataList ; // std: typedef list Data;
int main() {
Data k;
// back stuff
k.push_back(5);
k.push_back(6);
cout << k.back() << endl;
k.pop_back();
// front stuff
k.push_front(4);
k.push_front(3);
cout << k.front() << endl;
k.pop_front();
// forward iterator
Data::iterator pos;
for (pos = k.begin(); pos != k.end(); ++pos)
cout << *pos << endl;
// output and delete list
while (!k.empty()) {
cout << k.front() << endl;
k.pop_front();
}
k.push_front(5);
k.push_front(6);
// remove and erase
k.remove(5);
pos = k.begin();
k.erase(pos);
k.push_front(5);
k.push_front(6);
// copy constructor
Data l = k;
// assignment operator
Data m;
m = k;
return 0;
}
// List.h
struct Node;
classIterator List;
class List {
public:
typedef ListIterator iterator;
// constructor
List();
// destructor
virtual ~List();
// copy constructor
List(const List& k);
// assignment operator
List& operator=(const List& k);
// insert value in front of list
void push_front(double data);
// insert value in back of list
void push_back(double data);
// delete value from front of list
void pop_front();
// delete value from back of list
void pop_back();
// return value on front of list
double front() const;
// return value on back of list
double back() const;
// delete value specified by iterator
void erase(const iterator& i);
// delete all nodes with specified value
void remove(double data);
// return true if list is empty
bool empty() const;
// return reference to first element in list
iterator begin() const;
// return reference to one past last element in list
iterator end() const;
private:
Node *head; // head of list
};
class ListIterator {
public:
// default constructor
ListIterator() {
i = 0;
}
// construct iterator for given pointer (used for begin/end)
ListIterator(Node *p) {
i = p;
}
// convert iterator to Node*
operator Node*() const {
return i;
}
// test two iterators for not equal
bool operator!=(const ListIterator& k) const {
return i != k.i;
}
// preincrement operator
ListIterator& operator++() {
i = i->next;
return *this;
}
// return value associated with iterator
double& operator*() const {
return i->data;
}
private:
Node *i; // current value of iterator
};
list.cpp
// delete list
static void deleteList(Node *head) {
Node *p = head->next;
while (p != head) {
Node *next = p->next;
delete p;
p = next;
}
delete head;
}
// copy list
static void copyList(const Node *from, Node *&to) {
// create dummy header
to = new Node;
to->next = to->prev = to;
// copy nodes
for (Node *p = from->next; p != from; p = p->next) {
Node *t = new Node;
t.
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
Hi,
I have added the methods and main class as per your requirement. it is working fine now.
Highlighted the code changes.
MyLinkedListTest.java
public class MyLinkedListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyLinkedList list = new MyLinkedList();
list.addFirst(\"AAAAA\");
list.add(\"1\");
list.add(\"2\");
list.add(\"3\");
list.addLast(\"ZZZZZ\");
System.out.println(\"Linked List Elements : \"+list.toString());
System.out.println(\"First element: \"+list.getFirst());
System.out.println(\"Second element: \"+list.getLast());
System.out.println(\"Removed First Element: \"+list.removeFirst());
System.out.println(\"Now Linked List Elements : \"+list.toString());
System.out.println(\"Removed Last Element: \"+list.removeLast());
System.out.println(\"Now Linked List Elements : \"+list.toString());
System.out.println(\"Removed all element: \");
list.removeAll();
System.out.println(\"Now Linked List Elements : \"+list.toString());
}
}
MyLinkedList.java
public class MyLinkedList extends MyAbstractList {
private Node head, tail;
/** Create a default list */
public MyLinkedList() {
}
/** Create a list from an array of objects */
public MyLinkedList(E[] objects) {
super(objects);
}
/** Return the head element in the list */
public E getFirst() {
if (size == 0) {
return null;
}
else {
return (E)head.element;
}
}
/** Return the last element in the list */
public E getLast() {
if (size == 0) {
return null;
}
else {
return (E)tail.element;
}
}
/** Add an element to the beginning of the list */
public void addFirst(E e) {
Node newNode = new Node(e); // Create a new node
newNode.next = head; // link the new node with the head
head = newNode; // head points to the new node
size++; // Increase list size
if (tail == null) // the new node is the only node in list
tail = head;
}
/** Add an element to the end of the list */
public void addLast(E e) {
Node newNode = new Node(e); // Create a new for element e
if (tail == null) {
head = tail = newNode; // The new node is the only node in list
}
else {
tail.next = newNode; // Link the new with the last node
tail = tail.next; // tail now points to the last node
}
size++; // Increase size
}
/** Add a new element at the specified index in this list
* The index of the head element is 0 */
public void add(int index, E e) {
if (index == 0) {
addFirst(e);
}
else if (index >= size) {
addLast(e);
}
else {
Node current = head;
for (int i = 1; i < index; i++) {
current = current.next;
}
Node temp = current.next;
current.next = new Node(e);
(current.next).next = temp;
size++;
}
}
/** Remove the head node and
* return the object that is contained in the removed node. */
public E removeFirst() {
if (size == 0) {
return null;
}
else {
Node temp = head;
head = head.next;
size--;
if (head == null) {
tail = null;
}
return (E)temp.element;
}
}
/** Remove all elements from list */
public void removeAll() {
while(true) {
if (size == 0) {
break;
}
else {
Node temp = head;
head =.
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
import java.util.*; public class MyLinkedList{ public static void main(String[] args){ } } //copy
MyList to here interface MyList extends Collection { /* MyList will inherite all methods from
Collection public boolean add(E e); public boolean addAll(Collection extends E> c); public void
clear(); public boolean contains(Object o); public boolean containsAll(Collection> c); public
boolean isEmpty(); public boolean remove(Object o); public boolean removeAll(Collection> c);
public boolean retainAll(Collection> c); public int size(); public Object[] toArray(); public T[]
toArray(T[] arr); */ //abstract method public void add(int index, E e); public E get(int index);
public int indexOf(Object e); public int lastIndexOf(E e); public E remove(int index); public E
set(int index, E e); //default method @Override public default boolean add(E e){ add(size(), e);
return true; } @Override public default boolean isEmpty(){ return size()==0; } @Override
public default boolean remove(Object e){ if(indexOf(e) >= 0){ remove(indexOf(e)); return true;
} else{ return false; } } @Override public default boolean containsAll(Collection> c){
for(Object e : c){ if(!contains(e)){ return false; } } return true; } @Override public default
boolean addAll( Collection extends E> c){ for(E e : c){ add(e); } return true; } /* removeAll:
this[1,1,2,3] c[1,2,4] this.removeAll(c) [3] */ @Override public default boolean removeAll(
Collection> c){ for(Object e : c){ while(contains(e)){ this.remove(e); } } return true; } /*
retainAll this[1,1,2,3] c[1,2,4] this.retainAll(c) [1,1,2] */ @Override public default boolean
retainAll( Collection> c){ for(E e : this){ if(!c.contains(e)){ this.remove(e); } } return true; }
@Override public default Object[] toArray(){ Object[] results = new Object[size()]; int i = 0;
for(E e : this){ results[i++] = e; } return results; } /* T[] array */ @Override public default T[]
toArray(T[] array){ int i = 0; for(E e : this){ array[i++] = (T)e; } return array; } } class
TwoWayLinkedList implements MyList { //inner static class Node public class Node { E
element; Node next; Node previous; public Node(E e){ element = e; } } private Node head, tail;
private int size = 0; public TwoWayLinkedList(){ /* head = null; tail = null; size = 0; */ } public
TwoWayLinkedList(E[] objects){ } public E getFirst(){ return null; } public E getLast(){ return
null; } public void addFirst(E e){ } public void addLast(E e){ } public E removeFirst(){ return
null; } public E removeLast(){ return null; } @Override public void add(int index, E e){ }
@Override public E remove(int index){ return null; } @Override public void clear(){ }
@Override public boolean contains(Object e){ return false; } @Override public E get(int index){
return null; } @Override public int indexOf(Object e){ return -1; } @Override public int
lastIndexOf(Object e){ return -1; } @Override public E set(int index, E e){ return null; }
@Override public int size(){ return size; } //toString() @Override public String.
I need help on this 5 and 6. here is the code so far import jav.pdfmail931892
I need help on this 5 and 6.
here is the code so far:
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
* !!! Put in description of your program here !!!
*
* @author !!! your name here !!!
*
*/
public class AngryBirds extends JPanel
{
/**
* Here are some variables you are likely to find useful. I have created
* this variables outside of any method, so that they are available to all
* the methods.
*
* (Typically instance variables like this should be labeled as "public" or
* "private" but I have omitted this designation since you are not familiar
* with the meanings of these terms yet.)
*
* Show care not to create local variables with the same names as these
* ones!
*/
double timeInterval;
double velocity;
double angle;
/**
* paint
*
* Draws the Angry Birds simulation on the graphics window
*
* @param g the Graphics object for the window
*/
public void paint(Graphics g)
{
super.paint(g); // do not edit
// Set background color
Color skyBlueDay = new Color(135, 206, 250);
setBackground(skyBlueDay);
// Draw horizon (ground)
g.setColor(new Color(34, 139, 34)); // Green color for the ground
g.fillRect(0, getHeight() - 50, getWidth(), 50);
// Draw structure (e.g., a wooden block)
g.setColor(new Color(139, 69, 19)); // Brown color for the structure
g.fillRect(200, getHeight() - 100, 80, 80);
// Draw pigs in the structure (green round pigs with happy faces)
g.setColor(Color.GREEN);
// Pig 1
g.fillOval(215, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(220, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(222, getHeight() - 85, 2, 2); // Left eye
g.fillOval(226, getHeight() - 85, 2, 2); // Right eye
// Pig 2
g.setColor(Color.GREEN);
g.fillOval(235, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(240, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(242, getHeight() - 85, 2, 2); // Left eye
g.fillOval(246, getHeight() - 85, 2, 2); // Right eye
// Pig 3
g.setColor(Color.GREEN);
g.fillOval(255, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(260, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(262, getHeight() - 85, 2, 2); // Left eye
g.fillOval(266, getHeight() - 85, 2, 2); // Right eye
// Draw slingshot
g.setColor(new Color(139, 69, 19)); // Brown color for slingshot base
g.fillRect(50, getHeight() - 20, 20, 100); // Slingshot base
// Angry bird (Red bird)
g.setColor(new Color(255, 0, 0)); // Red color for the bird
g.fillOval(30, getHeight() - 50, 40, 40); // Body
g.setColor(Color.BLACK); // Bird's features
g.fillArc(40, getHeight() - 45, 10, 10, 0, -180); // Happy mouth
g.fillOval(35, getHeight() - 50, 8, 8); // Left eye
g.fillOval(45, getHeight() - 50, 8, 8); // Right eye
//put your code here
}//paint
/**
* init
*
* prompts user for information about the simulation
*/
public void init()
{
// prompt user for information
String time = ""; //used to store user input
do
{
time = JOpti.
More Related Content
Similar to How do I fix it in LinkedList.javaLinkedList.java Define.pdf
For this micro assignment, you must implement two Linked List functi.docxmckellarhastings
For this micro assignment, you must implement two Linked List functions. We will use the following
example Linked List:
2 0 -1 5 7
getElementAt(index)
This function should return the element (i.e. value) of the Nth item inside the linked list. For example,
on the Linked List above, getElementAt(0) should return 2; getElementAt(3) should return 5.
addElementAt(value, location)
This function should insert a new value at the given location. Note that the location supplied must be
within bounds of the LinkedList. For example, we cannot call addElementAt(4, 11) on the above Linked
List because 11 is beyond the size of the Linked List.
Here are some examples. If we call addElementAt(0, 1), the above Linked List would now look like:
1 2 0 -1 5 7
If we again call addElementAt(2, 123), we would get:
1 2 123 0 -1 5 7
Grading
Your submission will be graded based on the following:
1. [7] Your solution does not cause any runtime issues and your file passes all test cases
2. [3] Your code contains good style. For example,
You provide meaningful variable names
You provide sufficient and meaningful comments
Your code is well structured
@@@@@@@@@@@@@@@@@@@@@@@@
#ifndef LINKED_LIST_H
#define LINKED_LIST_H
#include
#include
#include "LinkedListNode.h"
#include
using namespace std;
template
class LinkedList
{
private:
//points to the front of the linked list
LinkedListNode *_front = nullptr;
//keeping track of size in a variable eliminates need to continually
//count LL boxes.
int _size = 0;
protected:
//creates a new LinkedListNode for us
virtual LinkedListNode *createNode(T value)
{
return new LinkedListNode < T > { value };
}
public:
//default constructor
LinkedList()
{
_front = nullptr;
}
//copy constructor
LinkedList(const LinkedList &other)
{
for (int i = 0; i < other.getSize(); i++)
{
addElement(other.getElementAt(i));
}
}
//move constructor
LinkedList(LinkedList &&other)
{
//take other's data
_front = other._front;
_size = other._size;
//reset other's pointers
other._front = nullptr;
}
//initializer list constructor
LinkedList(initializer_list values)
{
for (auto item : values)
{
addElement(item);
}
}
//Always remember to clean up pointers in destructor!
virtual ~LinkedList()
{
LinkedListNode *current = _front;
while (current != nullptr)
{
LinkedListNode *temp = current->getNext();
delete current;
current = temp;
}
}
//will return true if the LL is empty.
virtual bool isEmpty() const
{
return _size == 0;
}
//returns the size of the LL.
virtual int getSize() const
{
return _size;
}
.
File LinkedList.java Defines a doubly-l.pdfConint29
File: LinkedList.java
/**
* Defines a doubly-linked list class
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
}
/**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
/**
* Returns the value stored in the first node
* @precondition
* @return the value stored at node first
* @throws NoSuchElementException
*/
public T getFirst() throws NoSuchElementException {
return null;
}
/**
* Returns the value stored in the last node
* @precondition
* @return the value stored in the node last
* @throws NoSuchElementException
*/
public T getLast() throws NoSuchElementException {
return null;
}
/**
* Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
return null;
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return -1;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return false;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
return false;
}
/**** MUTATORS ****/
/**
* Creates a new first element
* @param data the data to insert at the front of the LinkedList
* @postcondition
*/
public void addFirst(T data) {
return;
}
/**
* Creates a new last element
* @param data the data to insert at the end of the LinkedList
* @postcondition
*/
public void addLast(T data) {
return;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
return;
}
/**
* removes the element at the front of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeFirst() throws NoSuchElementException {
return;
}
/**
* removes the element at the end of the LinkedList
* @precondition
* @postcondition
* @throws NoSuchElementException
*/
public void removeLast() throws NoSuchElementException {
return;
}
/**
* removes the element referenced by the iterator
* @precondition
* @pos.
tested on eclipseDoublyLinkedList class.pdfshanki7
//tested on eclipse
/*************DoublyLinkedList class*******************/
public class DoublyLinkedList {
/*Data member variable declaration*/
private Node head;
private int count;
/**default constructor*/
public DoublyLinkedList() {
/*Initializing variable*/
head=null;
count =0;
}
/*Insert at beginning in doubly linked list*/
public void insertBeginning(String name){
/*checking head is null then we will add node at head*/
if(head==null){
head=new Node(name, null, null);
count++;
}else{
/*else create temp node and setting next to head
* and then making temp to head*/
Node temp=new Node(name,null,null);
temp.setNext(head);
head.setPrev(temp);
head=temp;
count++;
}
}
public void printList(){
Node temp=head;
/*Printing element of doubly list*/
while(temp!=null){
System.out.println(temp.getData());
temp=temp.getNext();
}
}
/*Returning count from doubly linked list*/
public int count(){
return count;
}
/*deleting specific node from doubly linked list*/
public void delete(String name){
Node current=head,previous=head;
/*if it is head node to be deleted*/
if(head.getData().equals(name)){
current=head.getNext();
current.setPrev(null);
head=current;
previous=head;
}else{
/*If node in middle of list*/
while(current.getNext()!=null){
if(current.getData().equals(name)){
current.getNext().setPrev(previous);
previous.setNext(current.getNext());
count--;
break;
}
previous=current;
current=current.getNext();
}
/*If node is at last*/
if(current.getNext()==null){
if(current.getData().equals(name)){
previous.setNext(null);
count--;
}
}
}
}
/*deleting all nodes from list by assigning head to null
* and memory releasing take care by garbage collector*/
public void clear(){
head=null;
count=0;
}
/*Inserting element in alphabetic order*/
public void insertAlpha(String name){
Node current=head,previous=head;
/*creating new node*/
Node newNode=new Node(name,null,null);
/*if head node is null*/
if(head==null){
head=newNode;
count++;
}else{
/*please read about compareTo() method about returning value*/
if(head.getData().compareTo(name)>0){
newNode.setNext(head);
head=newNode;
count++;
}else{
/*condition for getting position of node to be inserted*/
while(current!=null&¤t.getData().compareTo(name)<=0){
previous=current;
current=current.getNext();
}
/*if node need to be inserted at last*/
if(current==null){
previous=newNode;
}else{
/*If node need to inserted in middle*/
newNode.setNext(current);
previous.setNext(newNode);
current.setPrev(newNode);
newNode.setPrev(previous);
}
count++;
}
}
}
/*Main method start*/
public static void main(String args[]){
/*creating object of doubly linked list*/
DoublyLinkedList doublyLinkedList=new DoublyLinkedList();
doublyLinkedList.insertBeginning(\"sunita\");
doublyLinkedList.insertBeginning(\"lalchand\");
/*calling alphabetic order method*/
doublyLinkedList.insertAlpha(\"ramsingh\");
doublyLinkedList.insertBeginning(\"Lokesh\");
doublyLinkedList.insertBeginning(\"Pritam\");
/*****printing list********/
doublyLinkedList.printL.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
Complete in JavaCardApp.javapublic class CardApp { private.pdfMAYANKBANSAL1981
Complete in Java
CardApp.java
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public void shuffle() {
}
/**
* Implements the bubble sort algorithm
* to sort cardList into sorted order, first by suit
* (alphabetical order)
* then by rank from 2 to A
*/
public void sort() {
}
/**
* Returns the deck of cards with each card separated
* by a blank space and a new line character at the end.
* @return The deck of cards as a string.
*/
@Override public String toString() {
return "";
}
}
Card.java
public class Card implements Comparable{
private String rank;
private String suit;
/**
* Constructor for the Card class
* @param rank the rank of card from 2 to A
* @param suit the suit of card C, D, H, or S
*/
public Card(String rank, String suit) {
}
/**
* Returns the card's rank
* @return rank a rank from 2 (low) to A (high)
*/
public String getRank() {
return "";
}
/**
* Returns the card's suit
* @return C, D, H, or S
*/
public String getSuit() {
return "";
}
/**
* Updates the card's rank
* @param rank a new rank
*/
public void setRank(String rank) {
}
/**
* Updates the card's suit
* @param suit the new suit
*/
public void setSuit(String suit) {
}
/**
* Concatenates rank and suit
* @return card rank and suit
*/
@Override public String toString() {
return "";
}
/**
* Overrides the equals method for Card
* Compares rank and suit and
* follows the equals formula given in
* Lesson 4 and also in Joshua Block's text
* @param obj another Object to compare for
* equality
* @return whether obj is a Card and, if so,
* of equal rank and suit
*/
@Override public boolean equals(Object obj) {
return false;
}
/**
* Orders two cards first by suit (alphabetically)
* Next by rank. "A" is considered the high card
* Order goes 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, A
* @param card another Card to compare to this Card
* @return a negative number if this comes before c
* and a positive number if c comes before this
* and 0 if this and c are equal according to the above
* equals method
*/
@Override public int compareTo(Card card) {
return -1;
}
}
}
LinkedList.Java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterato.
Please help me to make a programming project I have to sue them today- (1).pdfseoagam1
Please help me to make a programming project I have to sue them today. Please help me make a
UnsortedList and SortedList classes. The instructor give me The code of the List and AbstracList
Classes that 2 pages we do not modify them. Do not modify this pages!!! List.java import
java.util.Iterator; /** * Represents List interface. * * @author Varik Hoang * @version Sep 26,
2016 * @param is of any object type. */ public interface List { /** * The method returns the
current number of elements in the list. * * @return the current number of elements in the list
greater than or equal 0 */ public int getSize(); /** * The method returns whether the list is empty.
* * @return true if list is empty, false otherwise. */ public boolean isEmpty(); /** * The method
returns whether value is in the list. * * @param value the value is assigned * @return true if
value in the list, false otherwise. */ public boolean contains(Type value); /** * The method
inserts an element into the list. * * @param value the value is assigned */ public void insert(Type
value); /** * The method clears the list. */ public void clear(); /** * The method returns a string
representation of list contents. * * @return a string representation of list contents. * @see
Object#toString() */ @Override public String toString(); /** * /** * The method removes first
element occurrence from the list. * * @param value the value is assigned * @return the removed
value */ public Type remove(Type value); /** * The method returns the index of value. * *
@param value the value is assigned. * @return the index of value if in the list, -1 otherwise. */
public int getIndex(Type value); /** * The method removes value at the given index. * *
@param index the index must be in range of 0 and size * @return the removed value * @throws
IndexOutOfBoundsException if index less than 0 or index greater than * or equal size */ public
Type removeAtIndex(int index); /** * The method replaces the value at the given index with the
given value. * * @param index the index must be in range of 0 and size * @param value the
value is assigned * @throws IndexOutOfBoundsException if index less 0 or index greater than
size */ public void set(int index, Type value); /** * Returns the value at the given index in the
list. * * @param index the index must be in range of 0 and size * @throws
IndexOutOfBoundsException if index less than 0 or greater size * @return the value at the given
index in the list. */ public Type get(int index); /** * The method returns an iterator for this list. *
* @return an iterator for the list. */ public Iterator iterator(); } Do not modify this pages public
abstract class AbstractList implements List { /** * The reference to the last element */ protected
ListNode tail; /** * The size of the list */ protected int size; /** * The constructor that initiate the
tail and size references */ public AbstractList() { tail = null; size = 0; } @Override public int
getSize() { return size; } @Override public bool.
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
Exception to indicate that Singly LinkedList is empty. .pdfaravlitraders2012
/**
* Exception to indicate that Singly LinkedList is empty.
*/
class LinkedListEmptyException extends RuntimeException {
public LinkedListEmptyException() {
super();
}
public LinkedListEmptyException(String message) {
super(message);
}
}
/**
* Node class, which holds data and contains next which points to next Node.
*/
class Node {
public int data; // data in Node.
public Node next; // points to next Node in list.
/**
* Constructor
*/
public Node(int data) {
this.data = data;
}
/**
* Display Node\'s data
*/
public void displayNode() {
System.out.print(data + \" \");
}
}
/**
* Singly LinkedList class
*/
class LinkedList {
private Node first; // ref to first link on list
/**
* LinkedList constructor
*/
public LinkedList() {
first = null;
}
/**
* Insert New Node at first position
*/
public void insertFirst(int data) {
Node newNode = new Node(data); // Creation of New Node.
newNode.next = first; // newLink ---> old first
first = newNode; // first ---> newNode
}
/**
* Method deletes specific Node from Singly LinkedList in java.
*/
public Node deleteSpecificNode(int deleteKey) {
// Case1: when there is no element in LinkedList
if (first == null) { // means LinkedList in empty, throw exception.
throw new LinkedListEmptyException(
\"LinkedList doesn\'t contain any Nodes.\");
}
// Case2: when there is only one element in LinkedList- check whether we
// have to delete that Node or not.
if (first.data == deleteKey) { // means LinkedList consists of only one
// element, delete that.
Node tempNode = first; // save reference to first Node in tempNode-
// so that we could return saved reference.
first = first.next;
System.out.println(\"Node with data=\" + tempNode.data
+ \" was found on first and has been deleted.\");
return tempNode; // return deleted Node.
}
// Case3: when there are atLeast two elements in LinkedList
Node previous = null;
Node current = first;
while (current != null) {
if (current.data == deleteKey) {
System.out.println(\"Node with data=\" + current.data
+ \" has been deleted.\");
previous.next = current.next; // make previous node\'s next point
// to current node\'s next.
return current; // return deleted Node.
} else {
if (current.next == null) { // Means Node wasn\'t found.
System.out.println(\"Node with data=\" + deleteKey
+ \" wasn\'t found for deletion.\");
return null;
}
previous = current;
current = current.next; // move to next node.
}
}
return null;
}
/**
* Display Singly LinkedList
*/
public void displayLinkedList() {
System.out.print(\"Displaying LinkedList [first--->last]: \");
Node tempDisplay = first; // start at the beginning of linkedList
while (tempDisplay != null) { // Executes until we don\'t find end of
// list.
tempDisplay.displayNode();
tempDisplay = tempDisplay.next; // move to next Node
System.out.print(\"-->\");
}
System.out.println();
}
}
/**
* Main class - To test LinkedList.
*/
public class SinglyLinkedListDeleteNodeExample {
public static void main(String[] args) {
LinkedList linkedList = new LinkedList(); /.
package singlylinkedlist; public class Node { public String valu.pdfamazing2001
package singlylinkedlist;
public class Node {
public String value;
public Node next;
public Node(String value) {
this.value = value;
}
@Override
public String toString() {
return value;
}
}
SingleyLinkedList.java :
package singlylinkedlist;
import java.io.*;
import java.util.*;
/**
* Defines the interface for a singly-linked list.
*
*/
public interface SinglyLinkedList {
/**
* @return Reference to the first node. If the list is empty, this method
* returns null.
*/
public Node getFirst();
/**
* @return Reference to the last node . If the list is empty, this method
* returns null.
*/
public Node getLast();
/**
* @return Number of nodes in the list
*/
public int size();
/**
* @return true if the list has no nodes; false otherwise
*/
public boolean isEmpty();
/**
* Removes all nodes in the list.
*/
public void clear();
/**
* Inserts a new node with the given value after cursor.
*
* @param cursor
* The node to insert after. Set this to null to insert value as
the
* new first Node.
* @param value
* The value to insert
* @return a reference to the newly inserted Node
*/
public Node insert(Node cursor, String value);
/**
* Inserts a new node with the given value at the "end" of the list.
*
* @param value
* @return a reference to the newly inserted Node
*/
public Node append(String value);
/**
* Removes the node after the specified Node (cursor) from the list.
*
* @param cursor
* A reference to the Node to remove.
*/
public void removeAfter(Node cursor);
/**
* Returns a reference to the first Node containing the key, starting from
the
* given Node.
*
* @param start
* @param key
* @return a reference to the first Node containing the key
*/
public Node find(Node start, String key);
/**
* Prints the values of all the items in a list
*/
public void printWholeList();
}
SinglyLinkedTester.java:
package sbccunittest;
import static java.lang.Math.*;
import static java.lang.System.*;
import static org.apache.commons.lang3.StringUtils.*;
import static org.junit.Assert.*;
import static sbcc.Core.*;
import java.io.*;
import java.lang.reflect.*;
import java.nio.file.*;
import java.util.*;
import java.util.stream.*;
import org.apache.commons.lang3.*;
import org.junit.*;
import org.w3c.dom.ranges.*;
import sbcc.*;
import singlylinkedlist.*;
/**
* 09/16/2021
*
* @author sstrenn
*
*/
public class SinglyLinkedListTester {
public static String newline = System.getProperty("line.separator");
public static int totalScore = 0;
public static int extraCredit = 0;
public static boolean isZeroScore = false;
public static String scorePreamble = "";
@BeforeClass
public static void beforeTesting() {
totalScore = 0;
extraCredit = 0;
}
@AfterClass
public static void afterTesting() {
if (isZeroScore) {
totalScore = 0;
extraCredit = 0;
}
println(scorePreamble + "Estimated score (w/o late penalties, etc.) is:
" + totalScore + " out of 25.");
// If the project follows the naming convention, save the results in a
folder on
// the desktop. (Alex Kohanim)
try {
String directory =
substri.
Need Help!! C++ #include-iostream- #include-linkedlist-h- using namesp.pdfEdwardw5nSlaterl
Need Help!! C++
#include<iostream>
#include"linkedlist.h"
using namespace std;
/**
* @brief Destructor to destroy all nodes and release memory
*/
LinkedList::~LinkedList() {
//TODO: Add code here. Make sure memory is released properly.
}
/**
* @brief Purpose: Checks if the list is empty
* @return true if the list is empty, false otherwise
*/
bool LinkedList::isEmpty() const {
// TODO: Add code here
return count == 0;
}
/**
* @brief Get the number of nodes in the list
* @return int The number of nodes in the list
*/
int LinkedList::length() const{
//TODO: Add code here
}
/**
* @brief Convert the list to a string
*
*/
string LinkedList::toString() {
string str = "[";
Node *ptr = front;
if (ptr != nullptr) {
// Head node is not preceded by separator
str += to_string(ptr->val);
ptr = ptr->next;
}
while (ptr != nullptr) {
str += ", " + to_string(ptr->val);
ptr = ptr->next;
}
str += "]";
return str;
}
/**
* @brief Displays the contents of the list
*/
void LinkedList::displayAll() {
cout << toString() << endl;
}
//TODO: Add comments
void LinkedList::addRear(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
void LinkedList::addFront(T val) {
// TODO: Add code here
// consider the two cases of whether the list was empty
}
//TODO: Add comments
bool LinkedList::deleteFront(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
//TODO: Add comments
bool LinkedList::deleteRear(T &OldNum) {
// TODO: Add code here
// consider if the list was empty and return false if the list is empty
// consider the special case of deleting the only node in the list
}
/* --- harder ones for test 2 and 3 -- */
/**
* @brief Delete a node at a given position from the list. The
* node at position pos is deleted and the value of the deleted node is returned in val.
* The valid range of pos is 1 to count. pos = 1 is the first node, and pos = count is the last node.
* @param pos: position of the node to be deleted
* @param val: it is set to the value of the node to be deleted
* @return true: if the node was deleted successfully
* @return false: if the node was not deleted successfully because the position was out of range
*/
bool LinkedList::deleteAt(int pos, T &val) {
//TODO: Add code here
// check if the pos is valid first, then move the ptr to the rigth positon
// consider the special case of deleting the first node and the last node
// Do not forget to set value.
}
/**
* @brief Insert a value at a specified position in the list. The valid pos is in the range of 1 to
count+1.
* The value will be inserted before the node at the specified position. if pos = 1, the value will be
inserted
* at the front of the list. if pos = count+1, the value will be inserted at the rear of the list.
* @param pos: position to insert the value at.
* @param val: value to insert.
* @return true: if the value was inserte.
In this lab, we will write an application to store a deck of cards i.pdfcontact41
In this lab, we will write an application to store a deck of cards in a linked list, and then write
methods to sort and shuffle the deck.
Copy your completed LinkedList class from Lab 4 into the LinkedList.java file below.
Complete all methods of the Card class as described by the Javadoc comments. The class
contains both a suit and a rank. A suit is one of the categories into which the cards of a deck are
divided. The rank is the relative importance of the card within its suit.
Note that the Card constructor must convert any rank and suit letters to uppercase.
For the equals() method, be sure to follow the steps outlined in Lesson 4. How to implement the
compareTo() method is also covered in Lesson 4.
Note that you are not allowed to add any additional methods or member variables to this class or
you will not receive credit for this assignment.
Complete all methods of the CardApp class in the CardApp.java file as described by the Javadoc
comments.
You may add as many methods as you would like to this file, but are not allowed to add any
additional member variables.
The CardApp program must prompt for and allow the user to enter the name of any input file as
shown in the Example output below.
Implement the shuffle() method as specified in the comments for shuffle(). After you have
shuffled the deck of cards, write the result into a file named shuffled.txt.
Implement the sort() method using bubble sort from Lesson 4. First sort by suit in alphabetical
order and then by rank from 2 to A. The pseudocode for bubble sort is as follows:
After you have sorted the deck of cards, write the result to a file named sorted.txt.
The CardApp.java file also contains the main() method of the application. Use Develop mode to
test your CardApp code along with your Card and LinkedList code.
All input and output files must contain a list of cards, with each card stored on its own line. See
the example files cards1.txt and cards2.txt for example file formats.
[[[cards1.txt]]]
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
[[[cards2.txt]]]
AS
2S
3S
4S
5S
6S
7S
8S
9S
10S
JS
QS
KS
AC
2C
3C
4C
5C
6C
7C
8C
9C
10C
JC
QC
KC
AH
2H
3H
4H
5H
6H
7H
8H
9H
10H
JH
QH
KH
AD
2D
3D
4D
5D
6D
7D
8D
9D
10D
JD
QD
KD
[[[CardApp.java]]]
/**
* CardApp.java
* @author Your name
* @author Partner's name
* CIS 22C, Applied Lab 1
*/
public class CardApp {
private LinkedList list;
/**
* User interface prompts user, reads and writes files.
*/
public static void main(String[] args) {
}
/**
* Default constructor to initialize the deck
*/
public CardApp() {
}
/**
* Inserts a new Card into the deck
* @param card a playing Card
*/
public void addCard(Card card) {
}
/**
* Shuffles cards following this algorithm:
* First swaps first and last card
* Next, swaps every even card with the card 3
* nodes away from that card. Stops when it
* reaches the 3rd to last node
* Then, swaps ALL cards with the card that is
* 2 nodes away from it, starting at the 2nd card
* and stopping stopping at the 3rd to last node
*/
public vo.
public class CircularDoublyLinkedList-E- implements List-E- { privat.pdfChristopherkUzHunter
public class CircularDoublyLinkedList<E> implements List<E> {
private class Node {
private E value;
private Node next, prev;
public Node(E value, Node next, Node prev) {
this.value = value;
this.next = next;
this.prev = prev;
}
public Node(E value) {
this(value, null, null); // Delegate to other constructor
}
public Node() {
this(null, null, null); // Delegate to other constructor
}
public E getValue() {
return value;
}
public void setValue(E value) {
this.value = value;
}
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 void clear() {
value = null;
next = prev = null;
}
} // End of Node class
private class ListIterator implements Iterator<E> {
private Node nextNode;
public ListIterator() {
nextNode = header.getNext();
}
@Override
public boolean hasNext() {
return nextNode != trailer;
}
@Override
public E next() {
if (hasNext()) {
E val = nextNode.getValue();
nextNode = nextNode.getNext();
return val;
}
else
throw new NoSuchElementException();
}
} // End of ListIterator class, DO NOT REMOVE, TEST WILL FAIL
/* private fields */
private Node header, trailer; // "dummy" nodes
private int currentSize;
public CircularDoublyLinkedList() {
/**
* Set dummy nodes to point to each other
*
* --> header <--> trailer <--
* | |
* __________________________
*
*/
header = new Node();
trailer = new Node(null, header, header);
header.setNext(trailer);
header.setPrev(trailer);
currentSize = 0;
}
@Override
public void add(E obj) {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public void add(E elm, int index) {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public boolean remove(E obj) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public boolean remove(int index) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public int removeAll(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public E get(int index) {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public E set(int index, E newElement) {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public int firstIndexOf(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public int lastIndexOf(E obj) {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public E first() {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public E last() {
/*TODO ADD YOUR CODE HERE*/
return null;
}
@Override
public int size() {
/*TODO ADD YOUR CODE HERE*/
return -1;
}
@Override
public boolean isEmpty() {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public boolean contains(E obj) {
/*TODO ADD YOUR CODE HERE*/
return false;
}
@Override
public void clear() {
/*TODO ADD YOUR CODE HERE*/
}
@Override
public Iterator<E> iterator() {
return new ListIterator();
} //DO NOT DELETE, TESTS WILL FAIL
}
(Fill all TODO)
3. (20 pts) Head over to CircularDoublyLinkedList. java after finishing exercise 2. The
instructions for this exercis are as follows: - A circulardoublyl.
package com.java2novice.ds.linkedlist;
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
/**
* this class keeps track of each element information
* @author java2novice
*
*/
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
/**
* returns the size of the linked list
* @return
*/
public int size() { return size; }
/**
* return whether the list is empty or not
* @return
*/
public boolean isEmpty() { return size == 0; }
/**
* adds element at the starting of the linked list
* @param element
*/
public void addFirst(E element) {
Node tmp = new Node(element, head, null);
if(head != null ) {head.prev = tmp;}
head = tmp;
if(tail == null) { tail = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* adds element at the end of the linked list
* @param element
*/
public void addLast(E element) {
Node tmp = new Node(element, null, tail);
if(tail != null) {tail.next = tmp;}
tail = tmp;
if(head == null) { head = tmp;}
size++;
System.out.println(\"adding: \"+element);
}
/**
* this method walks forward through the linked list
*/
public void iterateForward(){
System.out.println(\"iterating forward..\");
Node tmp = head;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.next;
}
}
/**
* this method walks backward through the linked list
*/
public void iterateBackward(){
System.out.println(\"iterating backword..\");
Node tmp = tail;
while(tmp != null){
System.out.println(tmp.element);
tmp = tmp.prev;
}
}
/**
* this method removes element from the start of the linked list
* @return
*/
public E removeFirst() {
if (size == 0) throw new NoSuchElementException();
Node tmp = head;
head = head.next;
head.prev = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
/**
* this method removes element from the end of the linked list
* @return
*/
public E removeLast() {
if (size == 0) throw new NoSuchElementException();
Node tmp = tail;
tail = tail.prev;
tail.next = null;
size--;
System.out.println(\"deleted: \"+tmp.element);
return tmp.element;
}
public static void main(String a[]){
DoublyLinkedListImpl dll = new DoublyLinkedListImpl();
dll.addFirst(10);
dll.addFirst(34);
dll.addLast(56);
dll.addLast(364);
dll.iterateForward();
dll.removeFirst();
dll.removeLast();
dll.iterateBackward();
}
}
Solution
package com.java2novice.ds.linkedlist;
import java.util.NoSuchElementException;
public class DoublyLinkedListImpl {
private Node head;
private Node tail;
private int size;
public DoublyLinkedListImpl() {
size = 0;
}
/**
* this class keeps track of each element information
* @author java2novice
*
*/
private class Node {
E element;
Node next;
Node prev;
public Node(E element, Node next, Node prev) {
this.element = element;
this.next = next;
this.prev = prev;
}
}
/**
* returns the size of the l.
Labprogram.java
LinkedList.java
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
/**
* Converts the given array into a LinkedList
*
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
*
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
public T getFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
public T getIterator() throws NullPointerException {
if (iterator != null) {
return iterator.data;
} else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
public int getLength() {
return length;
}
public boolean isEmpty() {
return length == 0;
}
public boolean offEnd() {
return iterator == null;
}
public void addFirst(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if (isEmpty()) {
first = newNode;
last = newNode;
} else {
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
}
public void addIterator(T data) throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("addIterator Iterator is off end.");
}
if (iterator == last) {
addLast(data);
} else {
Node newNode = new Node(data);
Node next = iterator.next;
newNode.next = next;
newNode.prev = iterator;
iterator.next = newNode;
next.prev = newNode;
length++;
}
}
public void removeFirst() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == first) {
iterator = null;
}
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if (isEmpty()) {
throw new NoSuchElementException("The list is empty");
}
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == last) {
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
}
public void removeIterator() throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("Iterator is off the end opf the list.");
}
if (iterator .
public class MyLinkedListltE extends ComparableltEgtg.pdfaccostinternational
public class MyLinkedList<E extends Comparable<E>> {
private Node<E> head, tail;
private int size = 0; // Number of elements in the list
public MyLinkedList() {
head=tail=null;
size=0;
}
/** Return the head element in the list */
public E getFirst() {
if (size == 0) {
return null;
}
else {
return head.element;
}
}
/** Return the last element in the list */
public E getLast() {
if (size == 0) {
return null;
}
else {
return tail.element;
}
}
/** Add an element to the beginning of the list */
public void addFirst(E e) {
Node<E> newNode = new Node<>(e); // Create a new node
newNode.next = head; // link the new node with the head
head = newNode; // head points to the new node
size++; // Increase list size
if (tail == null) // the new node is the only node in list
tail = head;
}
/** Add an element to the end of the list */
public void addLast(E e) {
Node<E> newNode = new Node<>(e); // Create a new for element e
if (tail == null) {
head = tail = newNode; // The new node is the only node in list
}
else {
tail.next = newNode; // Link the new with the last node
tail = newNode; // tail now points to the last node
}
size++; // Increase size
}
public void add(int index, E e) {
if (index == 0) {
addFirst(e);
}
else if (index >= size) {
addLast(e);
}
else {
Node<E> current = head;
for (int i = 1; i < index; i++) {
current = current.next;
}
Node<E> temp = current.next;
current.next = new Node<>(e);
(current.next).next = temp;
size++;
}
}
//Add e to the end of this linkedlist
public void add(E e) {
// Left as Exercise
}
/** Remove the head node and
* return the object that is contained in the removed node. */
public E removeFirst() {
if (size == 0) {
return null;
}
else {
E temp = head.element;
head = head.next;
size--;
if (head == null) {
tail = null;
}
return temp;
}
}
/** Remove the last node and
* return the object that is contained in the removed node. */
public E removeLast() {
if (size == 0) {
return null;
}
else if (size == 1) {
E temp = head.element;
head = tail = null;
size = 0;
return temp;
}
else {
Node<E> current = head;
for (int i = 0; i < size - 2; i++) {
current = current.next;
}
E temp = tail.element;
tail = current;
tail.next = null;
size--;
return temp;
}
}
/** Remove the element at the specified position in this
* list. Return the element that was removed from the list. */
public E remove(int index) {
if (index < 0 || index >= size) {
return null;
}
else if (index == 0) {
return removeFirst();
}
else if (index == size - 1) {
return removeLast();
}
else {
Node<E> previous = head;
for (int i = 1; i < index; i++) {
previous = previous.next;
}
Node<E> current = previous.next;
previous.next = current.next;
size--;
return current.element;
}
}
/** Clear the list */
public void clear() {
size = 0;
head = tail = null;
}
/** Override toString() to return elements in the list in [] separated by , */
public String toString() {
StringBuilder result = new StringBuilder("[");
Node<E> current = head;
for (int i = 0; i < size; i++) {
result.append(current..
Consider a double-linked linked list implementation with the followin.pdfsales98
Consider a double-linked linked list implementation with the following node: struct Node {int
data; Node *prev; Node *next;} Write a copyList method that is not a member of any class.
The method should take a head pointer and return another pointer. Do not modify the input.
Solution
struct Node {
Node *prev; // previous node
Node *next; // next node
int data; // stored value
};
#include
#include \"List.h\" // std: #include
using namespace std;
typedef DataList ; // std: typedef list Data;
int main() {
Data k;
// back stuff
k.push_back(5);
k.push_back(6);
cout << k.back() << endl;
k.pop_back();
// front stuff
k.push_front(4);
k.push_front(3);
cout << k.front() << endl;
k.pop_front();
// forward iterator
Data::iterator pos;
for (pos = k.begin(); pos != k.end(); ++pos)
cout << *pos << endl;
// output and delete list
while (!k.empty()) {
cout << k.front() << endl;
k.pop_front();
}
k.push_front(5);
k.push_front(6);
// remove and erase
k.remove(5);
pos = k.begin();
k.erase(pos);
k.push_front(5);
k.push_front(6);
// copy constructor
Data l = k;
// assignment operator
Data m;
m = k;
return 0;
}
// List.h
struct Node;
classIterator List;
class List {
public:
typedef ListIterator iterator;
// constructor
List();
// destructor
virtual ~List();
// copy constructor
List(const List& k);
// assignment operator
List& operator=(const List& k);
// insert value in front of list
void push_front(double data);
// insert value in back of list
void push_back(double data);
// delete value from front of list
void pop_front();
// delete value from back of list
void pop_back();
// return value on front of list
double front() const;
// return value on back of list
double back() const;
// delete value specified by iterator
void erase(const iterator& i);
// delete all nodes with specified value
void remove(double data);
// return true if list is empty
bool empty() const;
// return reference to first element in list
iterator begin() const;
// return reference to one past last element in list
iterator end() const;
private:
Node *head; // head of list
};
class ListIterator {
public:
// default constructor
ListIterator() {
i = 0;
}
// construct iterator for given pointer (used for begin/end)
ListIterator(Node *p) {
i = p;
}
// convert iterator to Node*
operator Node*() const {
return i;
}
// test two iterators for not equal
bool operator!=(const ListIterator& k) const {
return i != k.i;
}
// preincrement operator
ListIterator& operator++() {
i = i->next;
return *this;
}
// return value associated with iterator
double& operator*() const {
return i->data;
}
private:
Node *i; // current value of iterator
};
list.cpp
// delete list
static void deleteList(Node *head) {
Node *p = head->next;
while (p != head) {
Node *next = p->next;
delete p;
p = next;
}
delete head;
}
// copy list
static void copyList(const Node *from, Node *&to) {
// create dummy header
to = new Node;
to->next = to->prev = to;
// copy nodes
for (Node *p = from->next; p != from; p = p->next) {
Node *t = new Node;
t.
Hi,I have added the methods and main class as per your requirement.pdfannaelctronics
Hi,
I have added the methods and main class as per your requirement. it is working fine now.
Highlighted the code changes.
MyLinkedListTest.java
public class MyLinkedListTest {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
MyLinkedList list = new MyLinkedList();
list.addFirst(\"AAAAA\");
list.add(\"1\");
list.add(\"2\");
list.add(\"3\");
list.addLast(\"ZZZZZ\");
System.out.println(\"Linked List Elements : \"+list.toString());
System.out.println(\"First element: \"+list.getFirst());
System.out.println(\"Second element: \"+list.getLast());
System.out.println(\"Removed First Element: \"+list.removeFirst());
System.out.println(\"Now Linked List Elements : \"+list.toString());
System.out.println(\"Removed Last Element: \"+list.removeLast());
System.out.println(\"Now Linked List Elements : \"+list.toString());
System.out.println(\"Removed all element: \");
list.removeAll();
System.out.println(\"Now Linked List Elements : \"+list.toString());
}
}
MyLinkedList.java
public class MyLinkedList extends MyAbstractList {
private Node head, tail;
/** Create a default list */
public MyLinkedList() {
}
/** Create a list from an array of objects */
public MyLinkedList(E[] objects) {
super(objects);
}
/** Return the head element in the list */
public E getFirst() {
if (size == 0) {
return null;
}
else {
return (E)head.element;
}
}
/** Return the last element in the list */
public E getLast() {
if (size == 0) {
return null;
}
else {
return (E)tail.element;
}
}
/** Add an element to the beginning of the list */
public void addFirst(E e) {
Node newNode = new Node(e); // Create a new node
newNode.next = head; // link the new node with the head
head = newNode; // head points to the new node
size++; // Increase list size
if (tail == null) // the new node is the only node in list
tail = head;
}
/** Add an element to the end of the list */
public void addLast(E e) {
Node newNode = new Node(e); // Create a new for element e
if (tail == null) {
head = tail = newNode; // The new node is the only node in list
}
else {
tail.next = newNode; // Link the new with the last node
tail = tail.next; // tail now points to the last node
}
size++; // Increase size
}
/** Add a new element at the specified index in this list
* The index of the head element is 0 */
public void add(int index, E e) {
if (index == 0) {
addFirst(e);
}
else if (index >= size) {
addLast(e);
}
else {
Node current = head;
for (int i = 1; i < index; i++) {
current = current.next;
}
Node temp = current.next;
current.next = new Node(e);
(current.next).next = temp;
size++;
}
}
/** Remove the head node and
* return the object that is contained in the removed node. */
public E removeFirst() {
if (size == 0) {
return null;
}
else {
Node temp = head;
head = head.next;
size--;
if (head == null) {
tail = null;
}
return (E)temp.element;
}
}
/** Remove all elements from list */
public void removeAll() {
while(true) {
if (size == 0) {
break;
}
else {
Node temp = head;
head =.
import java-util--- public class MyLinkedList{ public static void.pdfasarudheen07
import java.util.*; public class MyLinkedList{ public static void main(String[] args){ } } //copy
MyList to here interface MyList extends Collection { /* MyList will inherite all methods from
Collection public boolean add(E e); public boolean addAll(Collection extends E> c); public void
clear(); public boolean contains(Object o); public boolean containsAll(Collection> c); public
boolean isEmpty(); public boolean remove(Object o); public boolean removeAll(Collection> c);
public boolean retainAll(Collection> c); public int size(); public Object[] toArray(); public T[]
toArray(T[] arr); */ //abstract method public void add(int index, E e); public E get(int index);
public int indexOf(Object e); public int lastIndexOf(E e); public E remove(int index); public E
set(int index, E e); //default method @Override public default boolean add(E e){ add(size(), e);
return true; } @Override public default boolean isEmpty(){ return size()==0; } @Override
public default boolean remove(Object e){ if(indexOf(e) >= 0){ remove(indexOf(e)); return true;
} else{ return false; } } @Override public default boolean containsAll(Collection> c){
for(Object e : c){ if(!contains(e)){ return false; } } return true; } @Override public default
boolean addAll( Collection extends E> c){ for(E e : c){ add(e); } return true; } /* removeAll:
this[1,1,2,3] c[1,2,4] this.removeAll(c) [3] */ @Override public default boolean removeAll(
Collection> c){ for(Object e : c){ while(contains(e)){ this.remove(e); } } return true; } /*
retainAll this[1,1,2,3] c[1,2,4] this.retainAll(c) [1,1,2] */ @Override public default boolean
retainAll( Collection> c){ for(E e : this){ if(!c.contains(e)){ this.remove(e); } } return true; }
@Override public default Object[] toArray(){ Object[] results = new Object[size()]; int i = 0;
for(E e : this){ results[i++] = e; } return results; } /* T[] array */ @Override public default T[]
toArray(T[] array){ int i = 0; for(E e : this){ array[i++] = (T)e; } return array; } } class
TwoWayLinkedList implements MyList { //inner static class Node public class Node { E
element; Node next; Node previous; public Node(E e){ element = e; } } private Node head, tail;
private int size = 0; public TwoWayLinkedList(){ /* head = null; tail = null; size = 0; */ } public
TwoWayLinkedList(E[] objects){ } public E getFirst(){ return null; } public E getLast(){ return
null; } public void addFirst(E e){ } public void addLast(E e){ } public E removeFirst(){ return
null; } public E removeLast(){ return null; } @Override public void add(int index, E e){ }
@Override public E remove(int index){ return null; } @Override public void clear(){ }
@Override public boolean contains(Object e){ return false; } @Override public E get(int index){
return null; } @Override public int indexOf(Object e){ return -1; } @Override public int
lastIndexOf(Object e){ return -1; } @Override public E set(int index, E e){ return null; }
@Override public int size(){ return size; } //toString() @Override public String.
Similar to How do I fix it in LinkedList.javaLinkedList.java Define.pdf (20)
I need help on this 5 and 6. here is the code so far import jav.pdfmail931892
I need help on this 5 and 6.
here is the code so far:
import javax.swing.*;
import java.awt.*;
import java.util.*;
/**
* !!! Put in description of your program here !!!
*
* @author !!! your name here !!!
*
*/
public class AngryBirds extends JPanel
{
/**
* Here are some variables you are likely to find useful. I have created
* this variables outside of any method, so that they are available to all
* the methods.
*
* (Typically instance variables like this should be labeled as "public" or
* "private" but I have omitted this designation since you are not familiar
* with the meanings of these terms yet.)
*
* Show care not to create local variables with the same names as these
* ones!
*/
double timeInterval;
double velocity;
double angle;
/**
* paint
*
* Draws the Angry Birds simulation on the graphics window
*
* @param g the Graphics object for the window
*/
public void paint(Graphics g)
{
super.paint(g); // do not edit
// Set background color
Color skyBlueDay = new Color(135, 206, 250);
setBackground(skyBlueDay);
// Draw horizon (ground)
g.setColor(new Color(34, 139, 34)); // Green color for the ground
g.fillRect(0, getHeight() - 50, getWidth(), 50);
// Draw structure (e.g., a wooden block)
g.setColor(new Color(139, 69, 19)); // Brown color for the structure
g.fillRect(200, getHeight() - 100, 80, 80);
// Draw pigs in the structure (green round pigs with happy faces)
g.setColor(Color.GREEN);
// Pig 1
g.fillOval(215, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(220, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(222, getHeight() - 85, 2, 2); // Left eye
g.fillOval(226, getHeight() - 85, 2, 2); // Right eye
// Pig 2
g.setColor(Color.GREEN);
g.fillOval(235, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(240, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(242, getHeight() - 85, 2, 2); // Left eye
g.fillOval(246, getHeight() - 85, 2, 2); // Right eye
// Pig 3
g.setColor(Color.GREEN);
g.fillOval(255, getHeight() - 85, 20, 20); // Head
g.setColor(Color.BLACK); // Pig's features
g.fillArc(260, getHeight() - 80, 6, 6, 180, 180); // Happy mouth
g.fillOval(262, getHeight() - 85, 2, 2); // Left eye
g.fillOval(266, getHeight() - 85, 2, 2); // Right eye
// Draw slingshot
g.setColor(new Color(139, 69, 19)); // Brown color for slingshot base
g.fillRect(50, getHeight() - 20, 20, 100); // Slingshot base
// Angry bird (Red bird)
g.setColor(new Color(255, 0, 0)); // Red color for the bird
g.fillOval(30, getHeight() - 50, 40, 40); // Body
g.setColor(Color.BLACK); // Bird's features
g.fillArc(40, getHeight() - 45, 10, 10, 0, -180); // Happy mouth
g.fillOval(35, getHeight() - 50, 8, 8); // Left eye
g.fillOval(45, getHeight() - 50, 8, 8); // Right eye
//put your code here
}//paint
/**
* init
*
* prompts user for information about the simulation
*/
public void init()
{
// prompt user for information
String time = ""; //used to store user input
do
{
time = JOpti.
I need a substantive comment on this postThe formal structure of .pdfmail931892
I need a substantive comment on this post:
The formal structure of an organization is often shown in an organizational chart that displays
names, job titles, and lines of authority. At its core, a formal structure is meant to show how the
company operates at optimal health. My company utilizes an organizational chart (org chart) and
I am the one who updates it constantly. My company operates most closely under a functional
structure. A functional structure groups together people with similar skills who perform similar
tasks (Uhl-Bien, 2021). Our organizational structure starts with our founder and CEO, then
beneath him is the rest of the executive team. Each executive operates a different business unit
and has full teams below them as well. Depending on the business unit there are four to five
levels of employees from the top down. Our structure is a reflection of our goals, because each
business unit has goals that are specific to them, but that impact the overall organization. We also
have very distinct competencies within each business unit such as designers, project managers,
accountants, and account managers. They are all very specialized in what they do, and their role
is specific to their business unit..
I need help debugging some code. I am trying to read a text file and.pdfmail931892
I need help debugging some code. I am trying to read a text file and capture certain values from
said text file in order to initialize objects. The text file is of variaing size, and the line sizes are
not the same. All text files however follow a certain format. At some point there will be a header
[Territories] and underneath that will be information regarding these territories. The information
is presented as follows:
[Territories]
Cockpit01,658,355,Cockpit,Cockpit02,Territory33
Cockpit02,658,375,Cockpit,Cockpit01,Cockpit03,Territory33,Territory85
Cockpit03,658,395,Cockpit,Cockpit02,Territory85
Territory04,205,170,Left Cargo,Territory05,Territory10,Territory69,Territory11
Territory05,332,136,Left Cargo,Territory08,Territory06,Territory04
The lines are read as follows:
TerritoryName, pixel1, pixel2, continent, adjacent territories
There may be many or no adjacent territories, but the adjacent territories will continue after
continent until the end of the line. All values are delimited with ,. I am trying to capture the
values for TerritoryName, continent, and ALL adjacent territories, but my code is not working as
intended. This is what I have:
void Map::MapLoader(string filePath){
ifstream inputFile(filePath);
//if we cant find the file to open, return invalid
if(!inputFile){
cerr << "Invalid Input, failed to open file." << endl;
}
string line;
//this will be a map of territories
map territories;
while (getline(inputFile, line)) {
//skip all empty lines
if(line.empty()){
continue;
}
//if we find the territories tag, we begin to create territory objects and populate the vector
if(line.find("[Territories]") != string::npos){
while(getline(inputFile, line, ',') && !line.empty()){
istringstream iss(line);
string territoryName;
string continent;
int army;
string pixel1;
string pixel2;
//this is where I am having issues, must assign values using delimiter ','
iss >> territoryName >> pixel1 >> pixel2 >> continent;
//cout<<"territory name: " << territoryName <<" continent: "<< continent <<" pixel1:
"<< pixel1 <<" pixel 2: "<> adjacentTerritory){
currentTerritory.addAdjTerritories(adjacentTerritory);
}
territories[territoryName] = currentTerritory;
//adding the territory to our Map object
allTerritories = territories;
}
}
//if we do not find the [Territories] tag, we consider this file to be invalid
else{
// cerr << "Invalid map file. Please try again with a valid map file." << endl;
}
}
inputFile.close();
}
Any help with this would be greatly appreciated!.
I am trying to create a dynamic web project in Eclipse IDE that impl.pdfmail931892
I am trying to create a dynamic web project in Eclipse IDE that implements a CRUD
functionality and connects to a Film database in MySQL using the MVC pattern.
I have a Film class with the following attributes: int id; string title; string director; string date;
string genres; string characters; string synopsis; and with to string method.
I have the following methods in FilmDAO class: public ArrayList getAllFilms(), public Film
getFilmByID(int id), public ArrayList getFilmByTitle(string title), public boolean
updateFilm(Film film), public Boolean deleteFilm(int id), public Boolean insertFilm (Film film).
How do I write code for the following Servlets: 1. DeleteFilmServlet(do Post method to delete
film from database), 2. HomeServlet (do get method - to get all films from database and pass to
JSP). 3. InsertFilmServlet (do get method present web page with html form for inserting films
and do post method to process submitted form and insert film to db). 4. UpdateFilmServlet (do
get method present web page with html form for updating films and do post method process
submitted form: retrieve parameters and updata film in db).
Thanks..
Hi All!I have a question regrading creating a subgraph or rather v.pdfmail931892
Hi All!
I have a question regrading creating a subgraph or rather verifying that a connected or
unconnected graph has a connected or unconnected subgraph. I have a territory object, and each
of these objects have adjacent territories in the form of a string vector. Moreover, these territory
objects also have strin continent attached (every territory belongs to one and only one continent).
Is there a way in C++ to check to see if the contients for a connected subgraph? This is the code
I currently have running to check to see if that graph is connected, I wanted to know if there was
a way to check if the subgraphs are connected.
//walk function will traverse the map. This will be a recursive function to walk along the array
void Map::walk(int visit, bool visited[]){
visited[visit] = true;
for(int i = 0; i< vertCount; i++){
if(adjacencyMatrix[visit][i] == 1){
if(!visited[visit]){
walk(i, visited);
}
}
}
}
//verify if an edge is connected in a graph
bool Map::validate(){
bool connectedGraph=false;
bool connectedSubGraph=false;
bool notUniqueContinent = true;
bool* verifyArr = new bool[vertCount];
//the idea here is we will start at i=o, then traverse and check as we go along whether or not all
nodes are visble
for(int i=0; i.
HeadWallRam Inc. has expanded its reach globally and needs to re-lay.pdfmail931892
HeadWallRam Inc. has expanded its reach globally and needs to re-layout it is IP architecture.
The executive team has hired you as a consultant to propose a greenfield network design.
Follow all the same guidlines, restrictions and provisions from Lab Report writing. Include the
following information:
Full IP documentation (not just an IP Grid).
Network Diagram from Draw.io
VyOS route configuration (i.e the "set protocols static" commands) that would be used to
impliment all route entries in all routers. ONLY include the route commands
ISP provides a single DHCP public IP address
Plan for ONE connection to the internet connected to the US site
Interior IP ranges that the company uses (172.18.128.0/17)
Plan a STAR topology for the network core between sites
Plan for networks needed for connections between sites
Plan for all pieces of equipment to be located at one of the Head-Wall-Ram sites (No routers in
space)
Think about WHY you were called in and plan for that too!
US site has five subdivisions: Sales (40 hosts), Technical (600 hosts), Support (300 hosts), Local
Management (150 hosts), Global Management (300 hosts)
China site has six subdivisions: Manufacturing (800 hosts), Sales (20 hosts), Technical (1200
hosts), Support (50 hosts), Legal (40 hosts), R&D (200 hosts)
Europe site has seven subdivisions: Manufacturing (80 hosts), Sales (20 hosts), Technical (400
hosts), Support (40 hosts), Legal (30 hosts), R&D (200 hosts), Management (10 hosts).
For this part you will need to analyze the provided logfile part2.lo.pdfmail931892
For this part you will need to analyze the provided logfile part2.log. This files contains log
entries from a Linux server over the course of a month. The log entries are structured as follows:
Month Day H:M:S Level Component[ProcessID]: Content
For example the following log entry follows this format. Here the component is sshd(pam_unix)
and the content shows an authentication failure from remote host 218.188.2.4. Jun 14 15:16:01
combo sshd(pam_unix)[19939]: authentication failure; rhost=218.188.2.4
To analyze this logfile, perform the following steps:
1. Open the log file such that only a single line at a time is loaded into memory. [1]
2. Parse the log file and record the fields highlighted above. [5]
3. Create a datetime object to record the date. [2]
4. Find and print the three most commonly used components. [3]
5. Briefly describe these components as a comment in your program/notebook. One or two
sentences for each is sufficient. [3]
6. Create a plot that shows then these three common components were used throughout the day.
Divide the day into 2 periods (working hours and after hours) and plot the number of entrys for
each component during those periods. Working hours are between 9 and 5. [5].
Ginny (45) is unmarried. Who of the following may be Ginnys quali.pdfmail931892
Ginny (45) is unmarried. Who of the following may be Ginny's qualifying child for Child Tax
Credit purposes? None of the individuals listed provided more than half of their own support.
A. Ben. Ben is the five-year-old son of Ginny's boyfriend, Adam. Adam, Ben, and Ginny all
lived in the same household all year. Adam is required to file a return, but is willing to let Ginny
claim Ben.
B. Susannah. Susannah is Ginny's 20-year-old daughter. She lived with Ginny all year while
attending Your State University as a full-time student.
C. Tania. Tania is Ginny's nine-year-old daughter from a prior relationship. Tania lived with her
father, Greg, in another state for most of the year, but she stayed with Ginny for two weeks
during summer vacation.
D. Alexander. Alexander is Ginny's 12-year-old half-brother. Alexander's parents passed away
several years ago and he lived with Ginny all year..
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...Levi Shapiro
Letter from the Congress of the United States regarding Anti-Semitism sent June 3rd to MIT President Sally Kornbluth, MIT Corp Chair, Mark Gorenberg
Dear Dr. Kornbluth and Mr. Gorenberg,
The US House of Representatives is deeply concerned by ongoing and pervasive acts of antisemitic
harassment and intimidation at the Massachusetts Institute of Technology (MIT). Failing to act decisively to ensure a safe learning environment for all students would be a grave dereliction of your responsibilities as President of MIT and Chair of the MIT Corporation.
This Congress will not stand idly by and allow an environment hostile to Jewish students to persist. The House believes that your institution is in violation of Title VI of the Civil Rights Act, and the inability or
unwillingness to rectify this violation through action requires accountability.
Postsecondary education is a unique opportunity for students to learn and have their ideas and beliefs challenged. However, universities receiving hundreds of millions of federal funds annually have denied
students that opportunity and have been hijacked to become venues for the promotion of terrorism, antisemitic harassment and intimidation, unlawful encampments, and in some cases, assaults and riots.
The House of Representatives will not countenance the use of federal funds to indoctrinate students into hateful, antisemitic, anti-American supporters of terrorism. Investigations into campus antisemitism by the Committee on Education and the Workforce and the Committee on Ways and Means have been expanded into a Congress-wide probe across all relevant jurisdictions to address this national crisis. The undersigned Committees will conduct oversight into the use of federal funds at MIT and its learning environment under authorities granted to each Committee.
• The Committee on Education and the Workforce has been investigating your institution since December 7, 2023. The Committee has broad jurisdiction over postsecondary education, including its compliance with Title VI of the Civil Rights Act, campus safety concerns over disruptions to the learning environment, and the awarding of federal student aid under the Higher Education Act.
• The Committee on Oversight and Accountability is investigating the sources of funding and other support flowing to groups espousing pro-Hamas propaganda and engaged in antisemitic harassment and intimidation of students. The Committee on Oversight and Accountability is the principal oversight committee of the US House of Representatives and has broad authority to investigate “any matter” at “any time” under House Rule X.
• The Committee on Ways and Means has been investigating several universities since November 15, 2023, when the Committee held a hearing entitled From Ivory Towers to Dark Corners: Investigating the Nexus Between Antisemitism, Tax-Exempt Universities, and Terror Financing. The Committee followed the hearing with letters to those institutions on January 10, 202
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
1. How do I fix it in LinkedList.java?
LinkedList.java:
/**
* Defines a doubly-linked list class
* @author
* @author
*/
import java.util.NoSuchElementException;
public class LinkedList {
private class Node {
private T data;
private Node next;
private Node prev;
public Node(T data) {
this.data = data;
this.next = null;
this.prev = null;
}
}
private int length;
private Node first;
private Node last;
private Node iterator;
/**** CONSTRUCTORS ****/
/**
* Instantiates a new LinkedList with default values
* @postcondition
*/
public LinkedList() {
first = null;
last = null;
iterator = null;
length = 0;
}
2. /**
* Converts the given array into a LinkedList
* @param array the array of values to insert into this LinkedList
* @postcondition
*/
public LinkedList(T[] array) {
}
/**
* Instantiates a new LinkedList by copying another List
* @param original the LinkedList to copy
* @postcondition a new List object, which is an identical,
* but separate, copy of the LinkedList original
*/
public LinkedList(LinkedList original) {
}
/**** ACCESSORS ****/
public T getFirst() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return first.data;
}
public T getLast() throws NoSuchElementException {
if (isEmpty()){
throw new NoSuchElementException("The list is empty");
}
return last.data;
}
/**
3. * Returns the data stored in the iterator node
* @precondition
* @return the data stored in the iterator node
* @throw NullPointerException
*/
public T getIterator() throws NullPointerException {
if (iterator != null){
return iterator.data;
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Returns the current length of the LinkedList
* @return the length of the LinkedList from 0 to n
*/
public int getLength() {
return length;
}
/**
* Returns whether the LinkedList is currently empty
* @return whether the LinkedList is empty
*/
public boolean isEmpty() {
return length == 0;
}
/**
* Returns whether the iterator is offEnd, i.e. null
* @return whether the iterator is null
*/
public boolean offEnd() {
4. return iterator == null;
}
/**** MUTATORS ****/
public void addFirst(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
}
public void addLast(T data) {
Node newNode = new Node(data);
if(isEmpty()){
first = newNode;
last = newNode;
}
else{
last.next = newNode;
newNode.prev = last;
5. last = newNode;
}
length++;
}
/**
* Inserts a new element after the iterator
* @param data the data to insert
* @precondition
* @throws NullPointerException
*/
public void addIterator(T data) throws NullPointerException{
if(iterator != null){
Node newNode = new Node(data);
newNode.next = iterator.next;
iterator.next = newNode;
if (iterator == first){
first = newNode;
}
}else{
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/
public void removeFirst() throws NoSuchElementException {
if(isEmpty()){
throw new NoSuchElementException("The list is empty");
}
if(length == 1){
6. first = null;
last = null;
iterator = null;
}
else{
if(iterator == first){
iterator = null;
}
first = first.next;
first.prev = null;
}
length--;
}
public void removeLast() throws NoSuchElementException {
if(isEmpty()){
throw new NoSuchElementException("The list is empty");
}
if(length == 1){
first = null;
last = null;
iterator = null;
}
else{
if(iterator == last){
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
}
/**
7. * removes the element referenced by the iterator
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void removeIterator() throws NullPointerException {
if(iterator != null){
if(iterator == first){
first = first.next;
}else{
Node prev = first;
while(prev.next != iterator){
prev = prev.next;
}
prev.next = iterator.next;
if (iterator == last){
last = prev;
}
}
iterator = null;
}else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* places the iterator at the first node
8. * @postcondition
*/
public void positionIterator(){
iterator = first;
}
/**
* Moves the iterator one node towards the last
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void advanceIterator() throws NullPointerException {
if (!offEnd()){
iterator = iterator.next;
}else {
throw new NullPointerException("Iterator is off the end opf the list.");
}
}
/**
* Moves the iterator one node towards the first
* @precondition
* @postcondition
* @throws NullPointerException
*/
public void reverseIterator() throws NullPointerException {
if(iterator != first && iterator != null){
Node prev = first;
while (prev.next != iterator){
9. prev = prev.next;
}
iterator = prev;
}
}
public void clear() {
first = null;
last = null;
iterator = null;
length = 0;
}
public String toString() {
StringBuilder result = new StringBuilder();
Node temp = first;
while (temp != null){
result.append(temp.data + " ");
temp = temp.next;
}
return result.toString() + "n";
}
@SuppressWarnings("unchecked") //good practice to remove warning here
10. @Override
public boolean equals(Object obj) {
return false;
}
/**CHALLENGE METHODS*/
public void spinList(int numMoves) throws IllegalArgumentException{
}
public LinkedList altLists(LinkedList list) {
return null;
}
}
java.lang.NullPointerException
t java.util.Scanner; c class LabProgram { ublic static void main(String[] args) { LabProgram lab
= new LabProgram(); // Make and display list LinkedList Integer > list = new LinkedList
langlerangle() ; for (int i=1;i<4;i++ ) { list.addLast (i); } System.out.print("Created list: " +
list.toString()); // toString() has In System.out.println("list.offEnd(): " + list.offEnd());
System.out.println("list.positionIterator()"); list.positionIterator();
System.out.println("list.offEnd(): " + list.offEnd()); System.out.println("list.getIterator(): " +
list.getIterator()); System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.getIterator(): " + list.getIterator());
System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.getIterator(): " + list.getIterator()); System.out.println("list.
reverseIterator()"); list.reverseIterator(); System.out.println("list.getIterator(): " +
list.getIterator()); System.out.println("list.addIterator(42)"); list.addIterator (42);
System.out.println("list.getIterator(): " + list.getIterator()); System.out.print("list.tostring(): " +
list.tostring()); System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.advanceIterator()"); list.advanceIterator();
System.out.println("list.addIterator(99)"); list.addIterator(99); System.out.print("list.toString(): "
+ list.toString()); System.out.println("list.removeIterator()"); list. removeIterator();
System.out.print("list.toString(): " + list.toString()); System.out.println("list.offEnd(): " +