SlideShare a Scribd company logo
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 == first) {
removeFirst();
} else if (iterator == last) {
removeLast();
} else {
Node prev = iterator.prev;
Node next = iterator.next;
prev.next = next;
next.prev = prev;
iterator = null;
length--;
}
}
public void positionIterator() {
iterator = first;
}
public void advanceIterator() throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("Iterator is off the end opf the list.");
}
iterator = iterator.next;
}
public void reverseIterator() throws NullPointerException {
if (offEnd()) {
throw new NullPointerException("Iterator is off the end opf the list.");
}
iterator = 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";
}
public boolean equals(Object obj) {
return false;
}
public void spinList(int numMoves) throws IllegalArgumentException {
}
public LinkedList altLists(LinkedList list) {
return null;
}
} 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. Step 3: Implement LinkedList(T[ ] array) Constructor
LinkedList(T[] array) converts the given array into a LinkedList. public LinkedList(T[] array) [ )
Step 4: Implement the copy constructor Constructor LinkedList(LinkedList origina1) instantiates
a new LinkedList by copying another List. public LinkedList (LinkedList T original) { ) Step 5:
Implement boolean equals(Object o) Method equals () determines whether the given object is
another LinkedList, containing the same data in the same order, returning whether there is
equality. Step 6: Implement spinList (int numMoves) 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. Ex: [A,B,C],
numMoves =1[C,A,B] Ex: [1,2,3,4], numMoves =3[2,3,4,1] Ex: [2,3,4,1], numMoves
=5>[1,2,3,4] Step 7: Implement LinkedList T altLists (LinkedList T list) Method altLists ()
splices together two LinkedLists to create a third List which contains alternating values from the
original list and the given parameter. Ex: [1,2,3] and [4,5,6][1,4,2,5,3,6] Ex: [1,2,3,4] and
[5,6][1,5,2,6,3,4]
ic class LabProgram {. oublic static void main(string[] args) { LabProgram lab = new
LabProgram(); // Make and display Lists using array constructor LinkedList Integer > intList =
new LinkedList >( new Integer [ ] {1,2,3,4}); System.out.print("Created intList: " + intList); //
tostring() has (n LinkedList abcList = new LinkedList > (new String[] {"A","B","Cn});
System.out.print ("Created abcList: " + abcList); LinkedList String emptyList = new LinkedList
langlerangle() ; System.out.print("Created emptyList: " + emptyList); string[] array = null;
LinkedList String nullList = new LinkedList langlerangle( array ); System. out.print("Created
nullList: " + nullisist); // copy all using copy constructor LinkedList Integer > intcopy = new
LinkedList (intList); System.out.print("Created intcopy: " + intcopy); LinkedList String
abcCopy = new LinkedList > (abcList); System.out.print ("Created abccopy: " + abccopy);
LinkedList String emptyCopy = new LinkedList (emptyList); System.out.print ("Created
emptycopy: " + emptycopy); LinkedList String nullcopy = new LinkedList (nullList); System.
out.print("Created nullcopy: " + nullcopy); // Test equals System.out.println("intlist.equals(null):
" + intList.equals(nul1)); System.out.println("intList. equals(emptyList): " +
intList.equals(emptyList)); System. out.println("intList. equals (abcList): " + intList.equals
(abcList)); System.out.println("abcList.equals(intList): " + abcList.equals(intList));
System.out.println("intList. equals(intList): " + intList.equals(intList));
System.out.println("abcList. equals (abcList): " + abcList.equals (abcList));
System.out.println("abcList. equals(abccopy): " + abcList.equals (abccopy));
System.out.println("nullList. equals(nullcopy): " + nullList.equals(nullcopy));
System.out.println("emptyList.equals(emptycopy): " + emptyList.equals(emptycopy)); System.
out.println("emptyList.equals(nullList): " + emptyList.equals(nullList)); // Test spinlist
abcList.spinList( (0); System.out.print("abcList.spinList( ): " + abcList); abcList.spinList(1);
System.out.print("abcList.spinList(1): " + abcList); abcList.spinList( 2 );
System.out.print("abcList.spinList(2): " + abcList); abcList.spinList(3);
System.out.print("abcList.spinList(3): " + abcList); intlist.spinList( 3 );
System.out.print("intList.spinList(3): " + intList); intlist.spinList (5);
System.out.print("intlist.spinList(5): " + intList); emptyList.spinList(1);
System.out.print("emptyList.spinList(1): " + emptyList); nullList.spinList(1); System.
out.print("nulllist.spinList(1): " + nullList); // Test altlist LinkedList list123 = new LinkedList >(
new Integer [ ] {1,2,3}); System. out.print("Created list123: " + list123); LinkedList list456 =
new LinkedList >( new Integer [ ] {4,5,6}); System.out.print ("Created list456: " + list456);
System.out.print("list123.altLists(1ist456): " + list123.altLists(list456)); LinkedList Integer >
list1234 = new LinkedList >( new Integer [ ] {1,2,3,4}); System. out.print("Created list1234: " +
list1234); LinkedList list56 = new LinkedList > (new Integer [ ] {5,6}); System.
out.print("Created list56: " + list56); System.out.print("list1234.altLists(list56): " +
list1234.altLists(list56)); LinkedList < Integer > list12 = new LinkedList <>( new Integer [ ]
{1,2}); System. out.print("Created list12: " + list12); LinkedList list3456 = new LinkedList >(
new Integer[ ]{3,4,5,6}); System. out.print("Created list3456: " + list3456);
System.out.print("list12.altLists(list3456): " + list12.altLists(list3456));
System.out.print("abcList.altLists (emptyList): " + abcList.altLists(emptyList)); System.
out.print("abcList.altLists(nullList): " + abcList.altLists(nullList));

More Related Content

Similar to Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf

Stack linked list
Stack linked listStack linked list
Stack linked listbhargav0077
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
akkhan101
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdf
arpitcomputronics
 
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
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
BG Java EE Course
 
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
 
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
 
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
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
fantasiatheoutofthef
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
Lezione03
Lezione03Lezione03
Lezione03
robynho86
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
arpaqindia
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
Stewartt0kJohnstonh
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdf
ebrahimbadushata00
 
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
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
aromanets
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
kostikjaylonshaewe47
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
fmac5
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5ecomputernotes
 

Similar to Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf (20)

Stack linked list
Stack linked listStack linked list
Stack linked list
 
OrderTest.javapublic class OrderTest {       Get an arra.pdf
OrderTest.javapublic class OrderTest {         Get an arra.pdfOrderTest.javapublic class OrderTest {         Get an arra.pdf
OrderTest.javapublic class OrderTest {       Get an arra.pdf
 
I only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .pdfI only need help with four methods in the EmployeeManager class the .pdf
I only need help with four methods in the EmployeeManager class the .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
 
Basic data-structures-v.1.1
Basic data-structures-v.1.1Basic data-structures-v.1.1
Basic data-structures-v.1.1
 
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
 
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
 
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
 
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdfJAVA OOP project; desperately need help asap im begging.Been stuck.pdf
JAVA OOP project; desperately need help asap im begging.Been stuck.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
Lezione03
Lezione03Lezione03
Lezione03
 
Lezione03
Lezione03Lezione03
Lezione03
 
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdfJAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
JAVALAB #8 - ARRAY BASED LISTSThe next exercise is based on this.pdf
 
Please add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docxPlease add-modify the following to the original code using C# 1- Delet.docx
Please add-modify the following to the original code using C# 1- Delet.docx
 
Write a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.pdfWrite a java class LIST that outputsmainpublic class Ass.pdf
Write a java class LIST that outputsmainpublic class Ass.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
 
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdfCreat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
Creat Shape classes from scratch DETAILS You will create 3 shape cla.pdf
 
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdfImplement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
Implement a queue using a linkedlist (java)SolutionLinkedQueue.pdf
 
How do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdfHow do I fix it in javaLinkedList.java Defines a doubl.pdf
How do I fix it in javaLinkedList.java Defines a doubl.pdf
 
computer notes - Data Structures - 5
computer notes - Data Structures - 5computer notes - Data Structures - 5
computer notes - Data Structures - 5
 

More from freddysarabia1

In your application you choose your own Entity class - pick somethin.pdf
In your application you choose your own Entity class - pick somethin.pdfIn your application you choose your own Entity class - pick somethin.pdf
In your application you choose your own Entity class - pick somethin.pdf
freddysarabia1
 
operate a standardized, government-wide emergency medical service. Sit.pdf
operate a standardized, government-wide emergency medical service. Sit.pdfoperate a standardized, government-wide emergency medical service. Sit.pdf
operate a standardized, government-wide emergency medical service. Sit.pdf
freddysarabia1
 
Oakdale County School Busing The Oakdale County School Board was meeti.pdf
Oakdale County School Busing The Oakdale County School Board was meeti.pdfOakdale County School Busing The Oakdale County School Board was meeti.pdf
Oakdale County School Busing The Oakdale County School Board was meeti.pdf
freddysarabia1
 
Nina is the head of IT at a multinational company. She is promoting .pdf
Nina is the head of IT at a multinational company. She is promoting .pdfNina is the head of IT at a multinational company. She is promoting .pdf
Nina is the head of IT at a multinational company. She is promoting .pdf
freddysarabia1
 
Mr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdf
Mr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdfMr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdf
Mr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdf
freddysarabia1
 
Monitoring Outputs - The primary response includes all three parts.pdf
Monitoring Outputs - The primary response includes all three parts.pdfMonitoring Outputs - The primary response includes all three parts.pdf
Monitoring Outputs - The primary response includes all three parts.pdf
freddysarabia1
 
Module name is Networks 512 As the demand for faster and .pdf
Module name is Networks 512 As the demand for faster and .pdfModule name is Networks 512 As the demand for faster and .pdf
Module name is Networks 512 As the demand for faster and .pdf
freddysarabia1
 
MGT4209 Applied Project Management Project Charter � Celebration of Cu.pdf
MGT4209 Applied Project Management Project Charter � Celebration of Cu.pdfMGT4209 Applied Project Management Project Charter � Celebration of Cu.pdf
MGT4209 Applied Project Management Project Charter � Celebration of Cu.pdf
freddysarabia1
 
Modify the program written for the pay with overtime paid at time an.pdf
Modify the program written for the pay with overtime paid at time an.pdfModify the program written for the pay with overtime paid at time an.pdf
Modify the program written for the pay with overtime paid at time an.pdf
freddysarabia1
 
Maryam Blume decided to serve the children she was babysitting, ages.pdf
Maryam Blume decided to serve the children she was babysitting, ages.pdfMaryam Blume decided to serve the children she was babysitting, ages.pdf
Maryam Blume decided to serve the children she was babysitting, ages.pdf
freddysarabia1
 
Interpreting Visual Culture Assignment Choose one of the followin.pdf
Interpreting Visual Culture Assignment  Choose one of the followin.pdfInterpreting Visual Culture Assignment  Choose one of the followin.pdf
Interpreting Visual Culture Assignment Choose one of the followin.pdf
freddysarabia1
 
Kwame works for the Central Bank of Kenya and is attempting to forec.pdf
Kwame works for the Central Bank of Kenya and is attempting to forec.pdfKwame works for the Central Bank of Kenya and is attempting to forec.pdf
Kwame works for the Central Bank of Kenya and is attempting to forec.pdf
freddysarabia1
 

More from freddysarabia1 (12)

In your application you choose your own Entity class - pick somethin.pdf
In your application you choose your own Entity class - pick somethin.pdfIn your application you choose your own Entity class - pick somethin.pdf
In your application you choose your own Entity class - pick somethin.pdf
 
operate a standardized, government-wide emergency medical service. Sit.pdf
operate a standardized, government-wide emergency medical service. Sit.pdfoperate a standardized, government-wide emergency medical service. Sit.pdf
operate a standardized, government-wide emergency medical service. Sit.pdf
 
Oakdale County School Busing The Oakdale County School Board was meeti.pdf
Oakdale County School Busing The Oakdale County School Board was meeti.pdfOakdale County School Busing The Oakdale County School Board was meeti.pdf
Oakdale County School Busing The Oakdale County School Board was meeti.pdf
 
Nina is the head of IT at a multinational company. She is promoting .pdf
Nina is the head of IT at a multinational company. She is promoting .pdfNina is the head of IT at a multinational company. She is promoting .pdf
Nina is the head of IT at a multinational company. She is promoting .pdf
 
Mr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdf
Mr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdfMr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdf
Mr. D.I.Y. Group (M) Berhads (Mr. D.I.Y.) annual report for the fis.pdf
 
Monitoring Outputs - The primary response includes all three parts.pdf
Monitoring Outputs - The primary response includes all three parts.pdfMonitoring Outputs - The primary response includes all three parts.pdf
Monitoring Outputs - The primary response includes all three parts.pdf
 
Module name is Networks 512 As the demand for faster and .pdf
Module name is Networks 512 As the demand for faster and .pdfModule name is Networks 512 As the demand for faster and .pdf
Module name is Networks 512 As the demand for faster and .pdf
 
MGT4209 Applied Project Management Project Charter � Celebration of Cu.pdf
MGT4209 Applied Project Management Project Charter � Celebration of Cu.pdfMGT4209 Applied Project Management Project Charter � Celebration of Cu.pdf
MGT4209 Applied Project Management Project Charter � Celebration of Cu.pdf
 
Modify the program written for the pay with overtime paid at time an.pdf
Modify the program written for the pay with overtime paid at time an.pdfModify the program written for the pay with overtime paid at time an.pdf
Modify the program written for the pay with overtime paid at time an.pdf
 
Maryam Blume decided to serve the children she was babysitting, ages.pdf
Maryam Blume decided to serve the children she was babysitting, ages.pdfMaryam Blume decided to serve the children she was babysitting, ages.pdf
Maryam Blume decided to serve the children she was babysitting, ages.pdf
 
Interpreting Visual Culture Assignment Choose one of the followin.pdf
Interpreting Visual Culture Assignment  Choose one of the followin.pdfInterpreting Visual Culture Assignment  Choose one of the followin.pdf
Interpreting Visual Culture Assignment Choose one of the followin.pdf
 
Kwame works for the Central Bank of Kenya and is attempting to forec.pdf
Kwame works for the Central Bank of Kenya and is attempting to forec.pdfKwame works for the Central Bank of Kenya and is attempting to forec.pdf
Kwame works for the Central Bank of Kenya and is attempting to forec.pdf
 

Recently uploaded

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 

Recently uploaded (20)

Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 

Labprogram.javaLinkedList.javaimport java.util.NoSuchElementEx.pdf

  • 1. 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) { }
  • 2. /** * 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; }
  • 3. 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++; }
  • 4. 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 {
  • 5. 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 == first) { removeFirst(); } else if (iterator == last) { removeLast(); } else { Node prev = iterator.prev; Node next = iterator.next; prev.next = next; next.prev = prev; iterator = null; length--; } } public void positionIterator() {
  • 6. iterator = first; } public void advanceIterator() throws NullPointerException { if (offEnd()) { throw new NullPointerException("Iterator is off the end opf the list."); } iterator = iterator.next; } public void reverseIterator() throws NullPointerException { if (offEnd()) { throw new NullPointerException("Iterator is off the end opf the list."); } iterator = 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"; } public boolean equals(Object obj) { return false;
  • 7. } public void spinList(int numMoves) throws IllegalArgumentException { } public LinkedList altLists(LinkedList list) { return null; } } 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. Step 3: Implement LinkedList(T[ ] array) Constructor LinkedList(T[] array) converts the given array into a LinkedList. public LinkedList(T[] array) [ ) Step 4: Implement the copy constructor Constructor LinkedList(LinkedList origina1) instantiates a new LinkedList by copying another List. public LinkedList (LinkedList T original) { ) Step 5: Implement boolean equals(Object o) Method equals () determines whether the given object is another LinkedList, containing the same data in the same order, returning whether there is equality. Step 6: Implement spinList (int numMoves) 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. Ex: [A,B,C], numMoves =1[C,A,B] Ex: [1,2,3,4], numMoves =3[2,3,4,1] Ex: [2,3,4,1], numMoves =5>[1,2,3,4] Step 7: Implement LinkedList T altLists (LinkedList T list) Method altLists () splices together two LinkedLists to create a third List which contains alternating values from the original list and the given parameter. Ex: [1,2,3] and [4,5,6][1,4,2,5,3,6] Ex: [1,2,3,4] and [5,6][1,5,2,6,3,4] ic class LabProgram {. oublic static void main(string[] args) { LabProgram lab = new LabProgram(); // Make and display Lists using array constructor LinkedList Integer > intList = new LinkedList >( new Integer [ ] {1,2,3,4}); System.out.print("Created intList: " + intList); // tostring() has (n LinkedList abcList = new LinkedList > (new String[] {"A","B","Cn}); System.out.print ("Created abcList: " + abcList); LinkedList String emptyList = new LinkedList langlerangle() ; System.out.print("Created emptyList: " + emptyList); string[] array = null;
  • 8. LinkedList String nullList = new LinkedList langlerangle( array ); System. out.print("Created nullList: " + nullisist); // copy all using copy constructor LinkedList Integer > intcopy = new LinkedList (intList); System.out.print("Created intcopy: " + intcopy); LinkedList String abcCopy = new LinkedList > (abcList); System.out.print ("Created abccopy: " + abccopy); LinkedList String emptyCopy = new LinkedList (emptyList); System.out.print ("Created emptycopy: " + emptycopy); LinkedList String nullcopy = new LinkedList (nullList); System. out.print("Created nullcopy: " + nullcopy); // Test equals System.out.println("intlist.equals(null): " + intList.equals(nul1)); System.out.println("intList. equals(emptyList): " + intList.equals(emptyList)); System. out.println("intList. equals (abcList): " + intList.equals (abcList)); System.out.println("abcList.equals(intList): " + abcList.equals(intList)); System.out.println("intList. equals(intList): " + intList.equals(intList)); System.out.println("abcList. equals (abcList): " + abcList.equals (abcList)); System.out.println("abcList. equals(abccopy): " + abcList.equals (abccopy)); System.out.println("nullList. equals(nullcopy): " + nullList.equals(nullcopy)); System.out.println("emptyList.equals(emptycopy): " + emptyList.equals(emptycopy)); System. out.println("emptyList.equals(nullList): " + emptyList.equals(nullList)); // Test spinlist abcList.spinList( (0); System.out.print("abcList.spinList( ): " + abcList); abcList.spinList(1); System.out.print("abcList.spinList(1): " + abcList); abcList.spinList( 2 ); System.out.print("abcList.spinList(2): " + abcList); abcList.spinList(3); System.out.print("abcList.spinList(3): " + abcList); intlist.spinList( 3 ); System.out.print("intList.spinList(3): " + intList); intlist.spinList (5); System.out.print("intlist.spinList(5): " + intList); emptyList.spinList(1); System.out.print("emptyList.spinList(1): " + emptyList); nullList.spinList(1); System. out.print("nulllist.spinList(1): " + nullList); // Test altlist LinkedList list123 = new LinkedList >( new Integer [ ] {1,2,3}); System. out.print("Created list123: " + list123); LinkedList list456 = new LinkedList >( new Integer [ ] {4,5,6}); System.out.print ("Created list456: " + list456); System.out.print("list123.altLists(1ist456): " + list123.altLists(list456)); LinkedList Integer > list1234 = new LinkedList >( new Integer [ ] {1,2,3,4}); System. out.print("Created list1234: " + list1234); LinkedList list56 = new LinkedList > (new Integer [ ] {5,6}); System. out.print("Created list56: " + list56); System.out.print("list1234.altLists(list56): " + list1234.altLists(list56)); LinkedList < Integer > list12 = new LinkedList <>( new Integer [ ] {1,2}); System. out.print("Created list12: " + list12); LinkedList list3456 = new LinkedList >( new Integer[ ]{3,4,5,6}); System. out.print("Created list3456: " + list3456); System.out.print("list12.altLists(list3456): " + list12.altLists(list3456)); System.out.print("abcList.altLists (emptyList): " + abcList.altLists(emptyList)); System. out.print("abcList.altLists(nullList): " + abcList.altLists(nullList));