SlideShare a Scribd company logo
import java.util.*; public class MyLinkedList{ public static void main(String[] args){ } } //copy
MyList to here interface MyList extends Collection { /* MyList will inherite all methods from
Collection public boolean add(E e); public boolean addAll(Collection extends E> c); public void
clear(); public boolean contains(Object o); public boolean containsAll(Collection> c); public
boolean isEmpty(); public boolean remove(Object o); public boolean removeAll(Collection> c);
public boolean retainAll(Collection> c); public int size(); public Object[] toArray(); public T[]
toArray(T[] arr); */ //abstract method public void add(int index, E e); public E get(int index);
public int indexOf(Object e); public int lastIndexOf(E e); public E remove(int index); public E
set(int index, E e); //default method @Override public default boolean add(E e){ add(size(), e);
return true; } @Override public default boolean isEmpty(){ return size()==0; } @Override
public default boolean remove(Object e){ if(indexOf(e) >= 0){ remove(indexOf(e)); return true;
} else{ return false; } } @Override public default boolean containsAll(Collection> c){
for(Object e : c){ if(!contains(e)){ return false; } } return true; } @Override public default
boolean addAll( Collection extends E> c){ for(E e : c){ add(e); } return true; } /* removeAll:
this[1,1,2,3] c[1,2,4] this.removeAll(c) [3] */ @Override public default boolean removeAll(
Collection> c){ for(Object e : c){ while(contains(e)){ this.remove(e); } } return true; } /*
retainAll this[1,1,2,3] c[1,2,4] this.retainAll(c) [1,1,2] */ @Override public default boolean
retainAll( Collection> c){ for(E e : this){ if(!c.contains(e)){ this.remove(e); } } return true; }
@Override public default Object[] toArray(){ Object[] results = new Object[size()]; int i = 0;
for(E e : this){ results[i++] = e; } return results; } /* T[] array */ @Override public default T[]
toArray(T[] array){ int i = 0; for(E e : this){ array[i++] = (T)e; } return array; } } class
TwoWayLinkedList implements MyList { //inner static class Node public class Node { E
element; Node next; Node previous; public Node(E e){ element = e; } } private Node head, tail;
private int size = 0; public TwoWayLinkedList(){ /* head = null; tail = null; size = 0; */ } public
TwoWayLinkedList(E[] objects){ } public E getFirst(){ return null; } public E getLast(){ return
null; } public void addFirst(E e){ } public void addLast(E e){ } public E removeFirst(){ return
null; } public E removeLast(){ return null; } @Override public void add(int index, E e){ }
@Override public E remove(int index){ return null; } @Override public void clear(){ }
@Override public boolean contains(Object e){ return false; } @Override public E get(int index){
return null; } @Override public int indexOf(Object e){ return -1; } @Override public int
lastIndexOf(Object e){ return -1; } @Override public E set(int index, E e){ return null; }
@Override public int size(){ return size; } //toString() @Override public String toString(){
//[1,2,3] StringBuilder result = new StringBuilder("["); for(Node current = head; current != null;
current = current.next) { result.append(current.element); if(current != tail){ result.append(", "); }
} result.append("]"); return result.toString(); } @Override public Iterator iterator(){ return new
LinkedListIterator(); } //enhenced for loop //inner class private class LinkedListIterator
implements Iterator { private Node current = head; @Override public boolean hasNext(){ return
current != null; } @Override public E next(){ E e = current.element; current = current.next;
return e; } @Override public void remove(){ //not call next() yet if(current == head){ throw new
IllegalStateException("next() yet called yet"); } else if(current == null){
TwoWayLinkedList.this.removeLast(); } else{ int indexOfremoved = indexOf(current.element) -
1; TwoWayLinkedList.this.remove(indexOfremoved); } } } } *24.3 (Implement a doubly linked
list) The MyLinkedL ist class used in Listing 24.5 is a one-way directional linked list that
enables one-way traversal of the list. Modify the Node class to add the new data field name
previous to refer to the previous node in the list, as follows: public class Node { E element;
Node next: Node previous: public Node(E e) { element = e: } } Implement a new class named
TwoWayLinkedList that uses a doubly linked list to store elements. Define TwowayLinkedList
to implements MyList. You need to implement all the methods defined in MyLinkedList as well
as the methods listiterator () and listiterator (int index). Both return an instance of j ava.
util.Listiterator (see Figure 20.4 ). The former sets the cursor to the head of the list and the latter
to the element at the specified index.

More Related Content

Similar to import java-util--- public class MyLinkedList{ public static void.pdf

Favor composition over inheritance
Favor composition over inheritanceFavor composition over inheritance
Favor composition over inheritance
Kochih Wu
 
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
 
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
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
babitasingh698417
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
mail931892
 
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdfSOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
arccreation001
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
ravikapoorindia
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
aksahnan
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
mail931892
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
arrowmobile
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
syedabdul78662
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
fonecomp
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
shyamsunder1211
 
i am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdfi am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdf
sonunotwani
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2Technopark
 
Java generics
Java genericsJava generics
Java generics
Hosein Zare
 
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
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
pnaran46
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
mail931892
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanChinmay Chauhan
 

Similar to import java-util--- public class MyLinkedList{ public static void.pdf (20)

Favor composition over inheritance
Favor composition over inheritanceFavor composition over inheritance
Favor composition over inheritance
 
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
 
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
 
STAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdfSTAGE 2 The Methods 65 points Implement all the methods t.pdf
STAGE 2 The Methods 65 points Implement all the methods t.pdf
 
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdfHow do I fix it in LinkedList.javathis is what i didLabProgra.pdf
How do I fix it in LinkedList.javathis is what i didLabProgra.pdf
 
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdfSOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
 
ReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdfReversePoem.java ---------------------------------- public cl.pdf
ReversePoem.java ---------------------------------- public cl.pdf
 
So I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdfSo I have this code(StackInAllSocks) and I implemented the method but.pdf
So I have this code(StackInAllSocks) and I implemented the method but.pdf
 
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdfHow do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
How do I fix it in LinkedList.javaLabProgram.javaLinkedList.jav.pdf
 
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdfHere is the editable codeSolutionimport java.util.NoSuchEleme.pdf
Here is the editable codeSolutionimport java.util.NoSuchEleme.pdf
 
package ADTs public interface CollectionADTltTgt .pdf
package ADTs public interface CollectionADTltTgt      .pdfpackage ADTs public interface CollectionADTltTgt      .pdf
package ADTs public interface CollectionADTltTgt .pdf
 
I need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdfI need help creating a parametized JUnit test case for the following.pdf
I need help creating a parametized JUnit test case for the following.pdf
 
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdfCreate a class BinarySearchTree- A class that implements the ADT binar.pdf
Create a class BinarySearchTree- A class that implements the ADT binar.pdf
 
i am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdfi am looking for help on the method AddSorted and the method Copy only.pdf
i am looking for help on the method AddSorted and the method Copy only.pdf
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
 
Java generics
Java genericsJava generics
Java generics
 
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
 
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdfHow do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
How do I fix this error - Exception in thread -main- java-lang-NullPoi.pdf
 
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdfHow do I fix it in LinkedList.javaLinkedList.java Define.pdf
How do I fix it in LinkedList.javaLinkedList.java Define.pdf
 
Works Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay ChauhanWorks Applications Test - Chinmay Chauhan
Works Applications Test - Chinmay Chauhan
 

More from asarudheen07

In a study of the incidence of Ebola virus- 1000 subjects were followe.pdf
In a study of the incidence of Ebola virus- 1000 subjects were followe.pdfIn a study of the incidence of Ebola virus- 1000 subjects were followe.pdf
In a study of the incidence of Ebola virus- 1000 subjects were followe.pdf
asarudheen07
 
In a society of population N- the probability is p that a person has a.pdf
In a society of population N- the probability is p that a person has a.pdfIn a society of population N- the probability is p that a person has a.pdf
In a society of population N- the probability is p that a person has a.pdf
asarudheen07
 
In a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdf
In a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdfIn a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdf
In a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdf
asarudheen07
 
In a population where the effective population size (Ne) is 50 - allel.pdf
In a population where the effective population size (Ne) is 50 - allel.pdfIn a population where the effective population size (Ne) is 50 - allel.pdf
In a population where the effective population size (Ne) is 50 - allel.pdf
asarudheen07
 
In a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdf
In a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdfIn a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdf
In a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdf
asarudheen07
 
In a diploid plant species- gene R (with alleles R and r ) and gene F.pdf
In a diploid plant species- gene R (with alleles R and r ) and gene F.pdfIn a diploid plant species- gene R (with alleles R and r ) and gene F.pdf
In a diploid plant species- gene R (with alleles R and r ) and gene F.pdf
asarudheen07
 
In a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdf
In a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdfIn a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdf
In a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdf
asarudheen07
 
In a paternity case- a mother- Jenny- claimed that the father of her c.pdf
In a paternity case- a mother- Jenny- claimed that the father of her c.pdfIn a paternity case- a mother- Jenny- claimed that the father of her c.pdf
In a paternity case- a mother- Jenny- claimed that the father of her c.pdf
asarudheen07
 
In 2011 the Ministry of the environment reduced the acceptble concentr.pdf
In 2011 the Ministry of the environment reduced the acceptble concentr.pdfIn 2011 the Ministry of the environment reduced the acceptble concentr.pdf
In 2011 the Ministry of the environment reduced the acceptble concentr.pdf
asarudheen07
 
In a follow up study- you decide to test whether the prevalence of WNV.pdf
In a follow up study- you decide to test whether the prevalence of WNV.pdfIn a follow up study- you decide to test whether the prevalence of WNV.pdf
In a follow up study- you decide to test whether the prevalence of WNV.pdf
asarudheen07
 
In a digital age where computers are connected via network and data ar.pdf
In a digital age where computers are connected via network and data ar.pdfIn a digital age where computers are connected via network and data ar.pdf
In a digital age where computers are connected via network and data ar.pdf
asarudheen07
 
In a certain city- the daly consumplion of water (in milions or bters).pdf
In a certain city- the daly consumplion of water (in milions or bters).pdfIn a certain city- the daly consumplion of water (in milions or bters).pdf
In a certain city- the daly consumplion of water (in milions or bters).pdf
asarudheen07
 
In a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdf
In a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdfIn a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdf
In a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdf
asarudheen07
 
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdf
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdfIn a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdf
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdf
asarudheen07
 
In a 12-year grassland biodiversity experiment- 168 plots containing 1.pdf
In a 12-year grassland biodiversity experiment- 168 plots containing 1.pdfIn a 12-year grassland biodiversity experiment- 168 plots containing 1.pdf
In a 12-year grassland biodiversity experiment- 168 plots containing 1.pdf
asarudheen07
 
In 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdfIn 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdf
asarudheen07
 
In 2022- Juanita is married and files a joint tax return with her husb.pdf
In 2022- Juanita is married and files a joint tax return with her husb.pdfIn 2022- Juanita is married and files a joint tax return with her husb.pdf
In 2022- Juanita is married and files a joint tax return with her husb.pdf
asarudheen07
 
In 2021- El Salvador became the first in the world to adopt bitcoin as.pdf
In 2021- El Salvador became the first in the world to adopt bitcoin as.pdfIn 2021- El Salvador became the first in the world to adopt bitcoin as.pdf
In 2021- El Salvador became the first in the world to adopt bitcoin as.pdf
asarudheen07
 
In 2018- which of the following is true about medical schools in the U.pdf
In 2018- which of the following is true about medical schools in the U.pdfIn 2018- which of the following is true about medical schools in the U.pdf
In 2018- which of the following is true about medical schools in the U.pdf
asarudheen07
 
In 2013- the housing market started picking up- Were people getting th.pdf
In 2013- the housing market started picking up- Were people getting th.pdfIn 2013- the housing market started picking up- Were people getting th.pdf
In 2013- the housing market started picking up- Were people getting th.pdf
asarudheen07
 

More from asarudheen07 (20)

In a study of the incidence of Ebola virus- 1000 subjects were followe.pdf
In a study of the incidence of Ebola virus- 1000 subjects were followe.pdfIn a study of the incidence of Ebola virus- 1000 subjects were followe.pdf
In a study of the incidence of Ebola virus- 1000 subjects were followe.pdf
 
In a society of population N- the probability is p that a person has a.pdf
In a society of population N- the probability is p that a person has a.pdfIn a society of population N- the probability is p that a person has a.pdf
In a society of population N- the probability is p that a person has a.pdf
 
In a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdf
In a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdfIn a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdf
In a eukaryotic cell- mature mRNA contains Multiple Choice a poly A ta.pdf
 
In a population where the effective population size (Ne) is 50 - allel.pdf
In a population where the effective population size (Ne) is 50 - allel.pdfIn a population where the effective population size (Ne) is 50 - allel.pdf
In a population where the effective population size (Ne) is 50 - allel.pdf
 
In a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdf
In a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdfIn a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdf
In a prokaryotic cell- how would the mRNA be different from a tRNA- 1-.pdf
 
In a diploid plant species- gene R (with alleles R and r ) and gene F.pdf
In a diploid plant species- gene R (with alleles R and r ) and gene F.pdfIn a diploid plant species- gene R (with alleles R and r ) and gene F.pdf
In a diploid plant species- gene R (with alleles R and r ) and gene F.pdf
 
In a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdf
In a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdfIn a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdf
In a new TCP connection that uses Selective Acknowledgment- If -0-125-.pdf
 
In a paternity case- a mother- Jenny- claimed that the father of her c.pdf
In a paternity case- a mother- Jenny- claimed that the father of her c.pdfIn a paternity case- a mother- Jenny- claimed that the father of her c.pdf
In a paternity case- a mother- Jenny- claimed that the father of her c.pdf
 
In 2011 the Ministry of the environment reduced the acceptble concentr.pdf
In 2011 the Ministry of the environment reduced the acceptble concentr.pdfIn 2011 the Ministry of the environment reduced the acceptble concentr.pdf
In 2011 the Ministry of the environment reduced the acceptble concentr.pdf
 
In a follow up study- you decide to test whether the prevalence of WNV.pdf
In a follow up study- you decide to test whether the prevalence of WNV.pdfIn a follow up study- you decide to test whether the prevalence of WNV.pdf
In a follow up study- you decide to test whether the prevalence of WNV.pdf
 
In a digital age where computers are connected via network and data ar.pdf
In a digital age where computers are connected via network and data ar.pdfIn a digital age where computers are connected via network and data ar.pdf
In a digital age where computers are connected via network and data ar.pdf
 
In a certain city- the daly consumplion of water (in milions or bters).pdf
In a certain city- the daly consumplion of water (in milions or bters).pdfIn a certain city- the daly consumplion of water (in milions or bters).pdf
In a certain city- the daly consumplion of water (in milions or bters).pdf
 
In a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdf
In a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdfIn a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdf
In a city- 70- of the people prefer Candidate A- Suppose 30 people fro.pdf
 
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdf
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdfIn a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdf
In a 1-1-5 page document (APA format- 12-point font- double-spaced) an.pdf
 
In a 12-year grassland biodiversity experiment- 168 plots containing 1.pdf
In a 12-year grassland biodiversity experiment- 168 plots containing 1.pdfIn a 12-year grassland biodiversity experiment- 168 plots containing 1.pdf
In a 12-year grassland biodiversity experiment- 168 plots containing 1.pdf
 
In 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdfIn 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdf
In 2022- Lisa and Fred- a married couple- had taxable income of $311-4 (1).pdf
 
In 2022- Juanita is married and files a joint tax return with her husb.pdf
In 2022- Juanita is married and files a joint tax return with her husb.pdfIn 2022- Juanita is married and files a joint tax return with her husb.pdf
In 2022- Juanita is married and files a joint tax return with her husb.pdf
 
In 2021- El Salvador became the first in the world to adopt bitcoin as.pdf
In 2021- El Salvador became the first in the world to adopt bitcoin as.pdfIn 2021- El Salvador became the first in the world to adopt bitcoin as.pdf
In 2021- El Salvador became the first in the world to adopt bitcoin as.pdf
 
In 2018- which of the following is true about medical schools in the U.pdf
In 2018- which of the following is true about medical schools in the U.pdfIn 2018- which of the following is true about medical schools in the U.pdf
In 2018- which of the following is true about medical schools in the U.pdf
 
In 2013- the housing market started picking up- Were people getting th.pdf
In 2013- the housing market started picking up- Were people getting th.pdfIn 2013- the housing market started picking up- Were people getting th.pdf
In 2013- the housing market started picking up- Were people getting th.pdf
 

Recently uploaded

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
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
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
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
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 

import java-util--- public class MyLinkedList{ public static void.pdf

  • 1. import java.util.*; public class MyLinkedList{ public static void main(String[] args){ } } //copy MyList to here interface MyList extends Collection { /* MyList will inherite all methods from Collection public boolean add(E e); public boolean addAll(Collection extends E> c); public void clear(); public boolean contains(Object o); public boolean containsAll(Collection> c); public boolean isEmpty(); public boolean remove(Object o); public boolean removeAll(Collection> c); public boolean retainAll(Collection> c); public int size(); public Object[] toArray(); public T[] toArray(T[] arr); */ //abstract method public void add(int index, E e); public E get(int index); public int indexOf(Object e); public int lastIndexOf(E e); public E remove(int index); public E set(int index, E e); //default method @Override public default boolean add(E e){ add(size(), e); return true; } @Override public default boolean isEmpty(){ return size()==0; } @Override public default boolean remove(Object e){ if(indexOf(e) >= 0){ remove(indexOf(e)); return true; } else{ return false; } } @Override public default boolean containsAll(Collection> c){ for(Object e : c){ if(!contains(e)){ return false; } } return true; } @Override public default boolean addAll( Collection extends E> c){ for(E e : c){ add(e); } return true; } /* removeAll: this[1,1,2,3] c[1,2,4] this.removeAll(c) [3] */ @Override public default boolean removeAll( Collection> c){ for(Object e : c){ while(contains(e)){ this.remove(e); } } return true; } /* retainAll this[1,1,2,3] c[1,2,4] this.retainAll(c) [1,1,2] */ @Override public default boolean retainAll( Collection> c){ for(E e : this){ if(!c.contains(e)){ this.remove(e); } } return true; } @Override public default Object[] toArray(){ Object[] results = new Object[size()]; int i = 0; for(E e : this){ results[i++] = e; } return results; } /* T[] array */ @Override public default T[] toArray(T[] array){ int i = 0; for(E e : this){ array[i++] = (T)e; } return array; } } class TwoWayLinkedList implements MyList { //inner static class Node public class Node { E element; Node next; Node previous; public Node(E e){ element = e; } } private Node head, tail; private int size = 0; public TwoWayLinkedList(){ /* head = null; tail = null; size = 0; */ } public TwoWayLinkedList(E[] objects){ } public E getFirst(){ return null; } public E getLast(){ return null; } public void addFirst(E e){ } public void addLast(E e){ } public E removeFirst(){ return null; } public E removeLast(){ return null; } @Override public void add(int index, E e){ } @Override public E remove(int index){ return null; } @Override public void clear(){ } @Override public boolean contains(Object e){ return false; } @Override public E get(int index){ return null; } @Override public int indexOf(Object e){ return -1; } @Override public int lastIndexOf(Object e){ return -1; } @Override public E set(int index, E e){ return null; } @Override public int size(){ return size; } //toString() @Override public String toString(){ //[1,2,3] StringBuilder result = new StringBuilder("["); for(Node current = head; current != null; current = current.next) { result.append(current.element); if(current != tail){ result.append(", "); } } result.append("]"); return result.toString(); } @Override public Iterator iterator(){ return new LinkedListIterator(); } //enhenced for loop //inner class private class LinkedListIterator implements Iterator { private Node current = head; @Override public boolean hasNext(){ return current != null; } @Override public E next(){ E e = current.element; current = current.next; return e; } @Override public void remove(){ //not call next() yet if(current == head){ throw new IllegalStateException("next() yet called yet"); } else if(current == null){ TwoWayLinkedList.this.removeLast(); } else{ int indexOfremoved = indexOf(current.element) - 1; TwoWayLinkedList.this.remove(indexOfremoved); } } } } *24.3 (Implement a doubly linked list) The MyLinkedL ist class used in Listing 24.5 is a one-way directional linked list that enables one-way traversal of the list. Modify the Node class to add the new data field name previous to refer to the previous node in the list, as follows: public class Node { E element; Node next: Node previous: public Node(E e) { element = e: } } Implement a new class named
  • 2. TwoWayLinkedList that uses a doubly linked list to store elements. Define TwowayLinkedList to implements MyList. You need to implement all the methods defined in MyLinkedList as well as the methods listiterator () and listiterator (int index). Both return an instance of j ava. util.Listiterator (see Figure 20.4 ). The former sets the cursor to the head of the list and the latter to the element at the specified index.