Completed

Linked List Assignment

Linked List Assignment

Design

In class, we only discussed the implementation of a small number of operations for the Doubly Linked List data structure. For this assignment, you will write the implementation of a number of additional operations for the DoublyLinkedList class. Each operation is a separate new method of the class. Download the files [login to view URL] and [login to view URL] needed for the assignment.

You cannot modify any of the existing code for the DoublyLinkedList class. You cannot add any data members to the DoublyLinkedList class. You cannot add any nested classes to the DoublyLinkedList class. You cannot modify the nested Node class.

You will write code for all of the following methods for the DoublyLinkedList class. You must code each method with the most efficient runtime possible. You cannot use the iterator object of the doubly linked list class in implementing any of these methods. If needed, you can add additional methods to the DoublyLinkedList class but they must be declared private.

DoublyLinkedList<AnyType> clone()

This method returns a shallow copy of this DoublyLinkedList. The nodes of this DoublyLinkedList are cloned but the values themselves are not cloned.

boolean contains(AnyType value)

This method returns true if this list contains the specified value, otherwise it returns false.

int indexOf(AnyType value)

This method returns the index of the first occurrence of the specified value in this list, or -1 if this list does not contain the value.

int lastIndexOf(AnyType value)

This method returns the index of the last occurrence of the specified value in this list, or -1 if this list does not contain the value.

boolean removeFirstOccurrence(AnyType value)

This method removes the first occurrence of the specified value in this list (when traversing the list from head to tail). If the list does not contain the value, it is unchanged. The method returns true if the list contained the specified value, otherwise it returns false.

boolean removeLastOccurence(AnyType value)

This method removes the last occurrence of the specified value in this list (when traversing the list from head to tail). If the list does not contain the value, it is unchanged. The method returns true if the list contained the specified value, otherwise it returns false.

AnyType[] toArray()

This method returns an array containing all of the values in this list in proper sequence (from first to last value).

You do not need to write any other code for the assignment but you will need to thoroughly test your code implementation for the additional operations of the DoublyLinkedList class.

To grade your code, I compile and execute it within the Windows Command Prompt. Therefore, your program code should not use any java framework or library other than what is given in the Java Development Kit, JDK.

Grading Criteria

The total project is worth 20 points, broken down as follows:

1. If your code does not implement the task described in this assignment then the grade for the assignment is zero.

2. If your [login to view URL] file does not compile successfully then the grade for the assignment is zero.

3. If your [login to view URL] file produces runtime errors which prevents the grader from determining if

your code works properly then the grade for the assignment is zero.

If the program compiles successfully and executes without significant runtime errors then the grade computes as follows:

Followed proper submission instructions, 3 points:

1. Was the file submitted a zip file.

2. The zip file has the correct filename.

3. The contents of the zip file are in the correct format.

List Iterator execution:

4. The clone method works and executes properly, 3 points.

5. The contains method works and executes properly, 3 points.

6. The indexOf method works and executes properly, 2 points.

7. The lastIndexOf method works and executes properly, 2 points.

8. The removeFirstOccurrence method works and executes properly, 2 points.

9. The removeLastOccurrence method works and executes properly, 2 points.

10. The toArray method works and executes properly, 3 points.

Late submission penalty: assignments submitted after the due date are subjected to a 4 point deduction for each day late.

Submission Instructions

You’ll place the [login to view URL] file containing your implementation of the doubly linked list in a Zip file. The file should NOT be a 7z or rar file! You can follow the directions below for creating a zip file depending on the operating system running on the computer containing your assignment’s [login to view URL] file.

Creating a Zip file in Microsoft Windows (any version):

1. Right-click the [login to view URL] file to display a pop-up menu.

2. Click on Send to.

3. Click on Compressed (zipped) Folder.

4. Rename your Zip file as described below.

5. Follow the directions below to submit your assignment.

Creating a Zip file in Mac OS X:

1. Click File on the menu bar.

2. Click on Compress “[login to view URL]”.

3. Mac OS X creates the file DoublyLinkedList.java.zip.

4. Rename [login to view URL] as described below.

5. Follow the directions below to submit your assignment.

Save the Zip file with the filename having the following format: your last name,

followed by an underscore _, followed by your first name, followed by an underscore _, followed by the word Assignment1.

For example, if your name is John Doe then the filename would be: Doe_John_Assignment1

Once you submit your assignment you will not be able to resubmit it!

Make absolutely sure the assignment you want to submit is the assignment you want graded. There will be NO exceptions to this rule!

You will submit your Zip file via your CUNY Blackboard account. Follow these instructions:

Log onto your CUNY BlackBoard account.

Click on the CSCI 313 course link in the list of courses you're taking this semester. Click on Content in the green area on the left side of the webpage.

You will see the Assignment 1 – Linked List Assignment.

Click on the assignment.

Upload your Zip file and then click the submit button to submit your assignment.

————————-

[login to view URL]

import [login to view URL];

public interface List<AnyType>

{

void clear();

int size();

boolean isEmpty();

AnyType get(int index);

AnyType set(int index, AnyType newValue);

boolean add(AnyType newValue);

void add(int index, AnyType newValue);

AnyType remove(int index);

Iterator<AnyType> iterator();

—————————

[login to view URL]

import [login to view URL];

import [login to view URL];

import [login to view URL];

public class DoublyLinkedList<AnyType> implements List<AnyType>

{

private static class Node<AnyType>

{

private AnyType data;

private Node<AnyType> prev;

private Node<AnyType> next;

public Node(AnyType d, Node<AnyType> p, Node<AnyType> n)

{

setData(d);

setPrev(p);

setNext(n);

}

public AnyType getData() { return data; }

public void setData(AnyType d) { data = d; }

public Node<AnyType> getPrev() { return prev; }

public void setPrev(Node<AnyType> p) { prev = p; }

public Node<AnyType> getNext() { return next; }

public void setNext(Node<AnyType> n) { next = n; }

}

private int theSize;

private int modCount;

private Node<AnyType> header;

private Node<AnyType> trailer;

public DoublyLinkedList()

{

header = new Node<AnyType>(null, null, null);

trailer = new Node<AnyType>(null, null, null);

modCount = 0;

clear();

}

public void clear()

{

[login to view URL](trailer);

[login to view URL](header);

theSize = 0;

}

public int size()

{

return theSize;

}

public boolean isEmpty()

{

return (size() == 0);

}

private Node<AnyType> getNode(int index)

{

return (getNode(index, 0, size()-1));

}

private Node<AnyType> getNode(int index, int lower, int upper)

{

Node<AnyType> currNode;

if (index < lower || index > upper)

throw new IndexOutOfBoundsException();

int n = size();

if (index < n/2)

{

currNode = [login to view URL]();

for (int i = 0; i < index; i++) currNode = [login to view URL]();

}

else

{

currNode = trailer;

for (int i = n; i > index; i--) currNode = [login to view URL]();

}

return currNode;

}

public AnyType get(int index)

{

Node<AnyType> indexNode = getNode(index);

return [login to view URL]();

}

public AnyType set(int index, AnyType newValue)

{

Node<AnyType> indexNode = getNode(index);

AnyType oldValue = [login to view URL]();

[login to view URL](newValue);

return oldValue;

}

public boolean add(AnyType newValue)

{

add(size(), newValue);

return true;

}

public void add(int index, AnyType newValue)

{

addBefore(getNode(index, 0, size()), newValue);

}

private void addBefore(Node<AnyType> nextNode, AnyType newValue)

{

Node<AnyType> prevNode = [login to view URL]();

Node<AnyType> newNode = new Node<>(newValue, prevNode, nextNode);

[login to view URL](newNode);

[login to view URL](newNode);

theSize++;

modCount++;

}

public AnyType remove(int index)

{

return remove(getNode(index));

}

private AnyType remove(Node<AnyType> currNode)

{

Node<AnyType> prevNode = [login to view URL]();

Node<AnyType> nextNode = [login to view URL]();

[login to view URL](nextNode);

[login to view URL](prevNode);

theSize--;

modCount++;

return [login to view URL]();

}

public DoublyLinkedList<AnyType> clone()

{

}

public boolean contains(AnyType value)

{

}

public int indexOf(AnyType value)

{

}

public int lastIndexOf(AnyType value)

{

}

public boolean removeFirstOccurrence(AnyType value)

{

}

public boolean removeLastOccurence(AnyType value)

{

}

public AnyType[] toArray()

{

}

public Iterator<AnyType> iterator()

{

return new LinkedListIterator();

}

private class LinkedListIterator implements Iterator<AnyType>

{

private Node<AnyType> cursor;

private int expectedModCount;

private boolean okToRemove;

LinkedListIterator()

{

cursor = [login to view URL]();

expectedModCount = modCount;

okToRemove = false;

}

public boolean hasNext()

{

return (cursor != trailer);

}

public AnyType next()

{

if (modCount != expectedModCount)

throw new ConcurrentModificationException();

if (!hasNext())

throw new NoSuchElementException();

AnyType nextValue = [login to view URL]();

cursor = [login to view URL]();

okToRemove = true;

return nextValue;

}

public void remove()

{

if (modCount != expectedModCount)

throw new ConcurrentModificationException();

if (!okToRemove)

throw new IllegalStateException();

[login to view URL]([login to view URL]());

expectedModCount++;

okToRemove = false;

}

}

}

Skills: Java, Software Architecture, Windows Desktop

See more: assignment doubly linked list oops, design implement linked list whose objects represent polynomials, assignment linked list java, doubly linked list assignment operator, move assignment operator linked list c++, linked list assignment java, linked list assignment operator, linked list programming assignment, linked list overload =, linked list homework assignment, linked list operator[], linked list assignment java, linked list java assignment, java linked list assignment, programming assignment linked list, assignment doubly linked list, java assignment doubly linked list, doubly linked list assignment, linked list thought day, java project linked list assignemnt solution

About the Employer:
( 2 reviews ) Woodbury, United States

Project ID: #17166745

Awarded to:

koustav2006

HI...i am good at data structures including doubly linked lists in Java using object oriented programming design and patterns. i will deliver quality code with good amount of comments. please contact me as soon as poss More

$55 USD in 1 day
(109 Reviews)
5.8

3 freelancers are bidding on average $70 for this job

xinglong717

We are expert in Java and J2EE technologies and have completed numerous web/desktop projects and assignments. We have a total experience of more than eleven years in Java. Our skills and some of our completed projects More

$100 USD in 1 day
(17 Reviews)
4.5
gudgud96

Task looks manageable. PM for details

$55 USD in 1 day
(0 Reviews)
0.0