SlideShare a Scribd company logo
1 of 8
Download to read offline
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.pdfakkhan101
 
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 .pdfarpitcomputronics
 
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 .pdfarshin9
 
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.pdfalmaniaeyewear
 
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.pdfarorastores
 
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.pdfStewart29UReesa
 
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.pdffantasiatheoutofthef
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfravikapoorindia
 
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.pdfarpaqindia
 
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.docxStewartt0kJohnstonh
 
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.pdfebrahimbadushata00
 
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.pdfxlynettalampleyxc
 
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.pdfaromanets
 
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.pdfkostikjaylonshaewe47
 
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.pdffmac5
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 
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 .pdffreddysarabia1
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 
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 .pdffreddysarabia1
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 
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.pdffreddysarabia1
 

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

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationAadityaSharma884161
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 

Recently uploaded (20)

How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
ROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint PresentationROOT CAUSE ANALYSIS PowerPoint Presentation
ROOT CAUSE ANALYSIS PowerPoint Presentation
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.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));