SlideShare a Scribd company logo
1 of 8
Download to read offline
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 {
newNode.next = first;
first.prev = newNode;
first = newNode;
}
length++;
return;
}
public void addLast(T data) {
Node newNode = new Node(data);
if (length == 0) {
first = newNode;
last = newNode;
} else {
last.next = newNode;
newNode.prev = last;
last = newNode;
}
length++;
return;
}
public void addIterator(T data) throws NullPointerException{
if (iterator == null) {
throw new NullPointerException("Iterator is off end.");
}
Node newNode = new Node(data);
newNode.prev = iterator;
newNode.next = iterator.next;
if (iterator.next != null) {
iterator.next.prev = newNode;
}
iterator.next = newNode;
length++;
}
public void removeFirst() throws NoSuchElementException {
if (first == null) throw new NoSuchElementException();
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
first = first.next;
first.prev = first;
}
length--;
return;
}
public void removeLast() throws NoSuchElementException {
if (last == null) throw new NoSuchElementException();
if (length == 1) {
first = null;
last = null;
iterator = null;
} else {
if (iterator == last) {
iterator = null;
}
last = last.prev;
last.next = null;
}
length--;
return;
}
public void removeIterator() throws NullPointerException {
if (iterator == null) {
throw new NullPointerException("Iterator is off end.");
}
if (iterator.prev != null) {
iterator.prev.next = iterator.next;
}
if (iterator.next != null) {
iterator.next.prev = iterator.prev;
}
if (iterator == first) {
first = iterator.next;
}
if (iterator == last) {
last = iterator.prev;
}
iterator = null;
length--;
}
public void positionIterator(){
iterator = first;
}
public void advanceIterator() throws NullPointerException {
if (iterator == null) {
throw new NullPointerException("Iterator is off end.");
}
iterator = iterator.next;
}
public void reverseIterator() throws NullPointerException {
if (iterator == null) {
throw new NullPointerException("Iterator is off end.");
}
iterator = iterator.prev;
}
/**** ADDITIONAL OPERATIONS ****/
/**
* Re-sets LinkedList to empty as if the
* default constructor had just been called
*/
public void clear() {
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
Node temp = first;
while (temp != null) {
result.append(temp.data).append(" ");
temp = temp.next;
}
return result.toString() + "n";
}
/**
* Determines whether the given Object is
* another LinkedList, containing
* the same data in the same order
* @param obj another Object
* @return whether there is equality
*/
@SuppressWarnings("unchecked") //good practice to remove warning here
@Override public boolean equals(Object obj) {
return false;
}
/**CHALLENGE METHODS*/
/**
* 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 the front of the list
* For example: [1, 2, 3, 4, 5], numMoves = 2 -> [4, 5, 1, 2 ,3]
* For example: [1, 2, 3, 4, 5], numMoves = 4 -> [2, 3, 4, 5, 1]
* For example: [1, 2, 3, 4, 5], numMoves = 7 -> [4, 5, 1, 2 ,3]
* @param numMoves the number of times to move each node.
* @precondition numMoves >= 0
* @postcondition iterator position unchanged (i.e. still referencing
* the same node in the list, regardless of new location of Node)
* @throws IllegalArgumentException when numMoves < 0
*/
public void spinList(int numMoves) throws IllegalArgumentException{
}
/**
* Splices together two LinkedLists to create a third List
* which contains alternating values from this list
* and the given parameter
* For example: [1,2,3] and [4,5,6] -> [1,4,2,5,3,6]
* For example: [1, 2, 3, 4] and [5, 6] -> [1, 5, 2, 6, 3, 4]
* For example: [1, 2] and [3, 4, 5, 6] -> [1, 3, 2, 4, 5, 6]
* @param list the second LinkedList
* @return a new LinkedList, which is the result of
* interlocking this and list
* @postcondition this and list are unchanged
*/
public LinkedList altLists(LinkedList list) {
return null;
}
}

More Related Content

Similar to Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf

Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
MAYANKBANSAL1981
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
Stewart29UReesa
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
shalins6
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
JamesPXNNewmanp
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
arshin9
 
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
arkmuzikllc
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
arorastores
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
malavshah9013
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
xlynettalampleyxc
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
EricvtJFraserr
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
almaniaeyewear
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
kingsandqueens3
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
rohit219406
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
ankit11134
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
mckellarhastings
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
climatecontrolsv
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
contact41
 

Similar to Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf (20)

Complete in JavaCardApp.javapublic class CardApp { private.pdf
Complete in JavaCardApp.javapublic class CardApp {   private.pdfComplete in JavaCardApp.javapublic class CardApp {   private.pdf
Complete in JavaCardApp.javapublic class CardApp { private.pdf
 
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdfimport java-util-Iterator- import java-util-NoSuchElementException- im.pdf
import java-util-Iterator- import java-util-NoSuchElementException- im.pdf
 
Use C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdfUse C++ Write a function to merge two doubly linked lists. The input.pdf
Use C++ Write a function to merge two doubly linked lists. The input.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf2.(Sorted list array implementation)This sorted list ADT discussed .pdf
2.(Sorted list array implementation)This sorted list ADT discussed .pdf
 
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdfI keep getting NullPointerExcepetion, can someone help me with spinL.pdf
I keep getting NullPointerExcepetion, can someone help me with spinL.pdf
 
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdfHelp please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
Help please, I have attached LinkedList.cpp and LinkedList.hPlease.pdf
 
The LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdfThe LinkedList1 class implements a Linked list. class.pdf
The LinkedList1 class implements a Linked list. class.pdf
 
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdfClass DiagramIn the Assignment #10, you are given three files Ass.pdf
Class DiagramIn the Assignment #10, you are given three files Ass.pdf
 
This assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdfThis assignment and the next (#5) involve design and development of a.pdf
This assignment and the next (#5) involve design and development of a.pdf
 
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 Sorted number list implementation with linked listsStep 1 Inspec.pdf Sorted number list implementation with linked listsStep 1 Inspec.pdf
Sorted number list implementation with linked listsStep 1 Inspec.pdf
 
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdfProblem- Describe an algorithm for concatenating two singly linked lis.pdf
Problem- Describe an algorithm for concatenating two singly linked lis.pdf
 
Data Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdfData Structures in C++I am really new to C++, so links are really .pdf
Data Structures in C++I am really new to C++, so links are really .pdf
 
Please help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdfPlease help solve this in C++ So the program is working fin.pdf
Please help solve this in C++ So the program is working fin.pdf
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
 
For this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docxFor this micro assignment, you must implement two Linked List functi.docx
For this micro assignment, you must implement two Linked List functi.docx
 
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...Below is a given ArrayList class and Main class  Your Dreams Our Mission/tuto...
Below is a given ArrayList class and Main class Your Dreams Our Mission/tuto...
 
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdfPROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
PROBLEM STATEMENTIn this assignment, you will complete DoubleEnde.pdf
 
In this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdfIn this lab, we will write an application to store a deck of cards i.pdf
In this lab, we will write an application to store a deck of cards i.pdf
 

More from facevenky

Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdfFlag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
facevenky
 
Exercise 3 You are to code some simple music player application .pdf
Exercise 3  You are to code some simple music player application .pdfExercise 3  You are to code some simple music player application .pdf
Exercise 3 You are to code some simple music player application .pdf
facevenky
 
Exercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdfExercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdf
facevenky
 
Electronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdfElectronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdf
facevenky
 
Draw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdfDraw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdf
facevenky
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
facevenky
 
Do the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdfDo the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdf
facevenky
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
facevenky
 

More from facevenky (20)

Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdfFlag question Question 9Question 91 ptsMarty is a creative proble.pdf
Flag question Question 9Question 91 ptsMarty is a creative proble.pdf
 
Exercise 3 You are to code some simple music player application .pdf
Exercise 3  You are to code some simple music player application .pdfExercise 3  You are to code some simple music player application .pdf
Exercise 3 You are to code some simple music player application .pdf
 
Fiancial Statements. South Sea Baubles has the following (incomplete.pdf
Fiancial Statements. South Sea Baubles has the following (incomplete.pdfFiancial Statements. South Sea Baubles has the following (incomplete.pdf
Fiancial Statements. South Sea Baubles has the following (incomplete.pdf
 
Explore how the shift to digital platforms and online interactions has.pdf
Explore how the shift to digital platforms and online interactions has.pdfExplore how the shift to digital platforms and online interactions has.pdf
Explore how the shift to digital platforms and online interactions has.pdf
 
Exercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdfExercise2You are to develop a simple queue system for a customer .pdf
Exercise2You are to develop a simple queue system for a customer .pdf
 
Electronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdfElectronic Distribution has a defined benefit pension plan. Characte.pdf
Electronic Distribution has a defined benefit pension plan. Characte.pdf
 
Execution Steps of Building the Inverted Index is shown as below Exec.pdf
Execution Steps of Building the Inverted Index is shown as below Exec.pdfExecution Steps of Building the Inverted Index is shown as below Exec.pdf
Execution Steps of Building the Inverted Index is shown as below Exec.pdf
 
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdf
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdfElicitation TechniquesSeeking help for Elicitation plan for projec.pdf
Elicitation TechniquesSeeking help for Elicitation plan for projec.pdf
 
Draw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdfDraw a complete ERD that depicts the data model to record the requir.pdf
Draw a complete ERD that depicts the data model to record the requir.pdf
 
double linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdfdouble linked list header file code#include iostream#include.pdf
double linked list header file code#include iostream#include.pdf
 
Do the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdfDo the following well, read all directions, I asked this question be.pdf
Do the following well, read all directions, I asked this question be.pdf
 
Double linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdfDouble linked list header file below for FYI#include iostream.pdf
Double linked list header file below for FYI#include iostream.pdf
 
Digital Communication SystemsObjectives 1 To be able to demons.pdf
Digital Communication SystemsObjectives 1 To be able to demons.pdfDigital Communication SystemsObjectives 1 To be able to demons.pdf
Digital Communication SystemsObjectives 1 To be able to demons.pdf
 
Diagonal communicationa) is the traditional flow of communication .pdf
Diagonal communicationa) is the traditional flow of communication .pdfDiagonal communicationa) is the traditional flow of communication .pdf
Diagonal communicationa) is the traditional flow of communication .pdf
 
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdfDepicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
Depicted below is footnote #5 for Boeing, Co. for FYE 2021 and 2020,.pdf
 
Create a diagram for the following scenario The music streaming serv.pdf
Create a diagram for the following scenario The music streaming serv.pdfCreate a diagram for the following scenario The music streaming serv.pdf
Create a diagram for the following scenario The music streaming serv.pdf
 
Create a function that will read the saved projects from localStorag.pdf
Create a function that will read the saved projects from localStorag.pdfCreate a function that will read the saved projects from localStorag.pdf
Create a function that will read the saved projects from localStorag.pdf
 
Dawn Company general ledger shows the following account balances amo.pdf
Dawn Company general ledger shows the following account balances amo.pdfDawn Company general ledger shows the following account balances amo.pdf
Dawn Company general ledger shows the following account balances amo.pdf
 
Create a class Person with two instance variables of type String cal.pdf
Create a class Person with two instance variables of type String cal.pdfCreate a class Person with two instance variables of type String cal.pdf
Create a class Person with two instance variables of type String cal.pdf
 
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdf
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdfDave and his friend Stewart each owns 50 percent of KBS. During the .pdf
Dave and his friend Stewart each owns 50 percent of KBS. During the .pdf
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 

Copy your completed LinkedList class from Lab 3 into the LinkedList..pdf

  • 1. 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;
  • 2. 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 {
  • 3. 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 { newNode.next = first; first.prev = newNode; first = newNode; } length++; return; }
  • 4. public void addLast(T data) { Node newNode = new Node(data); if (length == 0) { first = newNode; last = newNode; } else { last.next = newNode; newNode.prev = last; last = newNode; } length++; return; } public void addIterator(T data) throws NullPointerException{ if (iterator == null) { throw new NullPointerException("Iterator is off end."); } Node newNode = new Node(data); newNode.prev = iterator; newNode.next = iterator.next; if (iterator.next != null) { iterator.next.prev = newNode; } iterator.next = newNode; length++; } public void removeFirst() throws NoSuchElementException { if (first == null) throw new NoSuchElementException(); if (length == 1) { first = null; last = null; iterator = null; } else {
  • 5. first = first.next; first.prev = first; } length--; return; } public void removeLast() throws NoSuchElementException { if (last == null) throw new NoSuchElementException(); if (length == 1) { first = null; last = null; iterator = null; } else { if (iterator == last) { iterator = null; } last = last.prev; last.next = null; } length--; return; } public void removeIterator() throws NullPointerException { if (iterator == null) { throw new NullPointerException("Iterator is off end."); } if (iterator.prev != null) { iterator.prev.next = iterator.next; } if (iterator.next != null) { iterator.next.prev = iterator.prev; }
  • 6. if (iterator == first) { first = iterator.next; } if (iterator == last) { last = iterator.prev; } iterator = null; length--; } public void positionIterator(){ iterator = first; } public void advanceIterator() throws NullPointerException { if (iterator == null) { throw new NullPointerException("Iterator is off end."); } iterator = iterator.next; } public void reverseIterator() throws NullPointerException { if (iterator == null) { throw new NullPointerException("Iterator is off end."); } iterator = iterator.prev; } /**** ADDITIONAL OPERATIONS ****/ /** * Re-sets LinkedList to empty as if the * default constructor had just been called */ public void clear() { } @Override
  • 7. public String toString() { StringBuilder result = new StringBuilder(); Node temp = first; while (temp != null) { result.append(temp.data).append(" "); temp = temp.next; } return result.toString() + "n"; } /** * Determines whether the given Object is * another LinkedList, containing * the same data in the same order * @param obj another Object * @return whether there is equality */ @SuppressWarnings("unchecked") //good practice to remove warning here @Override public boolean equals(Object obj) { return false; } /**CHALLENGE METHODS*/ /** * 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 the front of the list * For example: [1, 2, 3, 4, 5], numMoves = 2 -> [4, 5, 1, 2 ,3] * For example: [1, 2, 3, 4, 5], numMoves = 4 -> [2, 3, 4, 5, 1] * For example: [1, 2, 3, 4, 5], numMoves = 7 -> [4, 5, 1, 2 ,3] * @param numMoves the number of times to move each node. * @precondition numMoves >= 0 * @postcondition iterator position unchanged (i.e. still referencing * the same node in the list, regardless of new location of Node) * @throws IllegalArgumentException when numMoves < 0 */ public void spinList(int numMoves) throws IllegalArgumentException{
  • 8. } /** * Splices together two LinkedLists to create a third List * which contains alternating values from this list * and the given parameter * For example: [1,2,3] and [4,5,6] -> [1,4,2,5,3,6] * For example: [1, 2, 3, 4] and [5, 6] -> [1, 5, 2, 6, 3, 4] * For example: [1, 2] and [3, 4, 5, 6] -> [1, 3, 2, 4, 5, 6] * @param list the second LinkedList * @return a new LinkedList, which is the result of * interlocking this and list * @postcondition this and list are unchanged */ public LinkedList altLists(LinkedList list) { return null; } }