SlideShare a Scribd company logo
Note: Can someone help me with the private E get(int index, int currentIndex, Node n)method.
The code is not running. Also I need help with the public void add(int index, E element) method
too. Please use the parameters provided with the code to solve. package edu.ust.cisc; import
java.util.Iterator; import java.util.NoSuchElementException; public class CiscSortedLinkedList
> implements CiscList { /** * A reference to this list's dummy node. Its next reference should
refer to the node containing the first element * in this list, or it should refer to itself if the list is
empty. The next reference within the node containing * the last element in this list should refer to
dummy, thus creating a cyclic list. */ private Node dummy; /** * Number of elements in the list.
*/ private int size; /** * Constructs an empty CiscSortedLinkedList instance with a non-null
dummy node whose next reference refers to * itself. */ public CiscSortedLinkedList() { dummy
= new Node<>(null, null); dummy.next = dummy; } /** * Returns the number of elements in
this list. * * @return the number of elements in this list */ @Override public int size() { return
size; } /** * Returns {@code true} if this list contains no elements. * * @return {@code true} if
this list contains no elements */ @Override public boolean isEmpty() { return size==0; } /** *
Returns {@code true} if this list contains the specified element (compared using the {@code
equals} method). * This implementation should stop searching as soon as it is able to determine
that the specified element is not * present. * * @param o element whose presence in this list is to
be tested * @return {@code true} if this list contains the specified element * @throws
NullPointerException if the specified element is null */ @Override public boolean
contains(Object o) { if(o==null){ throw new NullPointerException(); } return
containsHelper(o,dummy.next); } private boolean containsHelper(Object o, Node node){
if(node== dummy){ return false; } else if(o.equals(node.data)){ return true; } else{ return
containsHelper(o,node.next); } } /** * Returns an iterator over the elements in this list in proper
sequence. * * @return an iterator over the elements in this list in proper sequence */ @Override
public Iterator iterator() { //return new Iterator (){ //private Node curr = dummy.next; //private
Node prev = dummy; //private boolean canRemove = false; return null; } /** * Returns an array
containing all of the elements in this list in proper sequence (from first to last element). *
The returned array will be "safe" in that no references to it are maintained by this list. (In other
words, * this method must allocate a new array even if this list is backed by an array). The caller
is thus free to modify * the returned array. * * @return an array containing all of the elements in
this list in proper sequence */ @Override public Object[] toArray() { Object[] arr = new
Object[size]; int i = 0; for(Node current = dummy;current!=null;current= current.next){ arr[i++]
= current.data; } return arr; } /** * {@link #toArray} recursive helper method. Adds the element
contained in the specified node to the specified index * in the specified array. Recursion stops
when the specified node is the dummy node. * * @param arr the array into which each element
in this list should be added * @param index the index into which the next element in this list
should be added * @param n the node containing the next element in this list to add to the array
*/ private void toArray(Object[] arr, int index, Node n) { } /** * Adds the specified element to
its sorted location in this list. * *
Lists may place the specified element at arbitrary locations if desired. In particular, an ordered
list will * insert the specified element at its sorted location. List classes should clearly specify in
their documentation * how elements will be added to the list if different from the default
behavior (end of this list). * * @param value element to be added to this list * @return {@code
true} * @throws NullPointerException if the specified element is null */ @Override public
boolean add(E value) { return false; } /** * {@link #add} recursive helper method. Adds the
specified value to the list in a new node following the specified * node (if that is the appropriate
location in the list). * * @param value element to be added to this list * @param n a reference to
the node possibly prior to the one created by this method */ private void add(E value, Node n) {
} /** * Removes the first occurrence of the specified element from this list, if it is present. If this
list does not * contain the element, it is unchanged. Returns {@code true} if this list contained
the specified element. This * implementation should stop searching as soon as it is able to
determine that the specified element is not * present. * * @param o element to be removed from
this list, if present * @return {@code true} if this list contained the specified element * @throws
NullPointerException if the specified element is null */ @Override public boolean
remove(Object o) { if(o==null){ throw new NullPointerException(); } Node curr = dummy.next;
Node prev = dummy; while (curr != dummy && !o.equals(curr.data)) { prev = curr; curr =
curr.next; } if (curr == dummy) { return false; } else { System.out.println("Removing
Data:"+curr.data); prev.next = curr.next; size--; return true; } } /** * {@link #remove} recursive
helper method. Removes the node following n if it contains the specified element. This *
implementation should stop searching as soon as it is able to determine that the specified element
is not * present. * * @param o element to be removed from this list, if present * @param n a
reference to the node prior to the one possibly containing the value to remove * @return */
private boolean remove(Object o, Node n) { return false; } /** * Removes all of the elements
from this list. The list will be empty after this call returns. @Override public void clear() {
dummy.next=dummy; size=0; } /** * Returns the element at the specified position in this list. *
* @param index index of the element to return * @return the element at the specified position in
this list * @throws IndexOutOfBoundsException if the index is out of range */ @Override
public E get(int index) { if(index<0 || index>=size){ throw new IndexOutOfBoundsException();
} Node curr = dummy.next; for(int i=0;i n) { if(index<0 || index>=size){ throw new
IndexOutOfBoundsException(); } Node curr = head; for(int i=0;i next_curr=curr.next;
curr.next=n; while(n.next) { n = n.next; //finding end of n headed linked list n.next =
next_curr;//adding rest linked list at end of n headed linked list } if(index==0) { return n; } else {
return head; } } /** * * @param index index of the element to replace * @param element
element to be stored at the specified position * @return the element previously at the specified
position * @throws UnsupportedOperationException if the {@code set} operation is not
supported by this list */ @Override public E set(int index, E element) { throw new
UnsupportedOperationException(); } /** * This operation is not supported by
CiscSortedLinkedList. * * @param index index at which the specified element is to be inserted *
@param element element to be inserted * @throws UnsupportedOperationException if the
{@code set} operation is not supported by this list */ @Override public void add(int index, E
element) { } /** * Appends all elements in the specified list to the end of this list, in the order
that they are returned by the * specified list's iterator. * * @param c list containing elements to
be added to this list * @return {@code true} if this list changed as a result of the call * @throws
NullPointerException if the specified list is null */ @Override public boolean addAll(CiscList
extends E> c) { return false; } /** * Removes the element at the specified position in this list.
Shifts any subsequent elements to the left * (subtracts one from their indices). Returns the
element that was removed from the list. * * @param index the index of the element to be
removed * @return the element previously at the specified position * @throws
IndexOutOfBoundsException if the index is out of range */ @Override public E remove(int
index) { return null; } /** * {@link #remove} recursive helper method. Removes the node
following n if it contains the element at the specified * index. * * @param index the index of the
element to be removed * @param currentIndex the index of the node parameter * @param n the
node containing the element at currentIndex * @return */ private E remove(int index, int
currentIndex, Node n) { return null; } /** * Returns the index of the first occurrence of the
specified element in this list, or -1 if this list does not * contain the element (compared using the
{@code equals} method). This implementation should stop searching as * soon as it is able to
determine that the specified element is not present. * @param o element to search for * @return
the index of the first occurrence of the specified element in this list, or -1 if this list does not *
contain the element * @throws NullPointerException if the specified element is null */
@Override public int indexOf(Object o) { if(o==null){ throw new NullPointerException(); }
return indexOf(o,0, dummy.next); } /** * {@link #indexOf} recursive helper method. Returns
currentIndex if the element contained in the node parameter is * equal to the specified element to
search for. This implementation should stop searching as soon as it is able to * determine that the
specified element is not present. * * @param o element to search for * @param currentIndex the
index of the node parameter * @param n the node containing the element at currentIndex *
@return the index of the first occurrence of the specified element in this list, or -1 if this list does
not * contain the element */ private int indexOf(Object o, int currentIndex, Node n) {
if(n.data.equals(o)){ return currentIndex; } else if(n==dummy){ return -1; } else
if(n.data.compareTo((E)o)>0){ return -1; } else{ return indexOf(o,currentIndex+1,n.next); } }
/** * Returns a string representation of this list. This string should consist of a comma separated
list of values * contained in this list, in order, surrounded by square brackets (examples: [3, 6, 7]
and []). * * @return a string representation of this list */ public String toString() { return null; }
/** * {@link #toString} recursive helper method. Returns a string representation of this list,
beginning with the * element in the specified node * * @param n the node containing the next
element to append to the string * @return a string representation of this list, beginning with the
element in the specified node */ private String toString(Node n) { return null; } private static
class Node { private E data; private Node next; private Node(E data, Node next) { this.data =
data; this.next = next; } } private class CiscLinkedListIterator implements Iterator { /** * A
reference to the node containing the next element to return, or to the dummy node if there are no
more * elements to return. */ private Node nextNode; /** * Constructs an iterator ready to return
the first element in the list (if present). */ public CiscLinkedListIterator() { } /** * Returns
{@code true} if the iteration has more elements. (In other words, returns {@code true} if *
{@link #next} would return an element rather than throwing an exception.) * * @return {@code
true} if the iteration has more elements */ @Override public boolean hasNext() { return false; }
/** * Returns the next element in the iteration. * * @return the next element in the iteration *
@throws NoSuchElementException if the iteration has no more elements */ @Override public E
next() { return null; } } }
Note- Can someone help me with the private E get(int index- int curren (1).docx

More Related Content

Similar to Note- Can someone help me with the private E get(int index- int curren (1).docx

import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
deepakangel
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
maheshkumar12354
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
accostinternational
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
rishabjain5053
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
info430661
 
we using java dynamicArray package modellinearpub imp.pdf
we using java dynamicArray    package modellinearpub   imp.pdfwe using java dynamicArray    package modellinearpub   imp.pdf
we using java dynamicArray package modellinearpub imp.pdf
adityagupta3310
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
SHIVA101531
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
tesmondday29076
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
udit652068
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
arcellzone
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdf
gudduraza28
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
aggarwalopticalsco
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
ezonesolutions
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
VictorXUQGloverl
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
fantasiatheoutofthef
 
A popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdfA popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdf
arsarees
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
Conint29
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
ankit11134
 

Similar to Note- Can someone help me with the private E get(int index- int curren (1).docx (20)

import java.util.Iterator; import java.util.NoSuchElementException; .pdf
  import java.util.Iterator; import java.util.NoSuchElementException; .pdf  import java.util.Iterator; import java.util.NoSuchElementException; .pdf
import java.util.Iterator; import java.util.NoSuchElementException; .pdf
 
For this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdfFor this lab you will complete the class MyArrayList by implementing.pdf
For this lab you will complete the class MyArrayList by implementing.pdf
 
Implementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdfImplementation The starter code includes List.java. You should not c.pdf
Implementation The starter code includes List.java. You should not c.pdf
 
public class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdfpublic class MyLinkedListltE extends ComparableltEgtg.pdf
public class MyLinkedListltE extends ComparableltEgtg.pdf
 
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdfImplement the interface you wrote for Lab B (EntryWayListInterface)..pdf
Implement the interface you wrote for Lab B (EntryWayListInterface)..pdf
 
Given below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdfGiven below is the completed implementation of MyLinkedList class. O.pdf
Given below is the completed implementation of MyLinkedList class. O.pdf
 
we using java dynamicArray package modellinearpub imp.pdf
we using java dynamicArray    package modellinearpub   imp.pdfwe using java dynamicArray    package modellinearpub   imp.pdf
we using java dynamicArray package modellinearpub imp.pdf
 
Lecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docxLecture 18Dynamic Data Structures and Generics (II).docx
Lecture 18Dynamic Data Structures and Generics (II).docx
 
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdfDividing a linked list into two sublists of almost equal sizesa. A.pdf
Dividing a linked list into two sublists of almost equal sizesa. A.pdf
 
Implement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdfImplement the following specification of UnsortedType using circular.pdf
Implement the following specification of UnsortedType using circular.pdf
 
package linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdfpackage linkedLists- import java-util-Iterator- --- A class representi.pdf
package linkedLists- import java-util-Iterator- --- A class representi.pdf
 
we using java code DynamicArrayjava Replace all .pdf
we using java code   DynamicArrayjava   Replace all .pdfwe using java code   DynamicArrayjava   Replace all .pdf
we using java code DynamicArrayjava Replace all .pdf
 
please read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdfplease read the steps below and it will tell you what we usi.pdf
please read the steps below and it will tell you what we usi.pdf
 
Describe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdfDescribe an algorithm for concatenating two singly linked lists L and.pdf
Describe an algorithm for concatenating two singly linked lists L and.pdf
 
please i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdfplease i need help Im writing a program to test the merge sort alg.pdf
please i need help Im writing a program to test the merge sort alg.pdf
 
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
Java Foundations StackADT-java ---  - Defines the interface to a stack.docxJava Foundations StackADT-java ---  - Defines the interface to a stack.docx
Java Foundations StackADT-java --- - Defines the interface to a stack.docx
 
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdfLabProgram.javaimport java.util.NoSuchElementException;public .pdf
LabProgram.javaimport java.util.NoSuchElementException;public .pdf
 
A popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdfA popular implementation of List is ArrayList- Look up how to instanti.pdf
A popular implementation of List is ArrayList- Look up how to instanti.pdf
 
File LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdfFile LinkedList.java Defines a doubly-l.pdf
File LinkedList.java Defines a doubly-l.pdf
 
please read below it will tell you what we are using L.pdf
please read below it will tell you what we are using   L.pdfplease read below it will tell you what we are using   L.pdf
please read below it will tell you what we are using L.pdf
 

More from VictorzH8Bondx

OVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docx
OVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docxOVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docx
OVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docx
VictorzH8Bondx
 
Overview Dagnostic coding and reporting guidelines for outpatient serv.docx
Overview Dagnostic coding and reporting guidelines for outpatient serv.docxOverview Dagnostic coding and reporting guidelines for outpatient serv.docx
Overview Dagnostic coding and reporting guidelines for outpatient serv.docx
VictorzH8Bondx
 
out of Stanford University and founded the blood testing company clini.docx
out of Stanford University and founded the blood testing company clini.docxout of Stanford University and founded the blood testing company clini.docx
out of Stanford University and founded the blood testing company clini.docx
VictorzH8Bondx
 

More from VictorzH8Bondx (20)

A large bullfrog hops onto a prime spot on log and shoves off a turtle.docx
A large bullfrog hops onto a prime spot on log and shoves off a turtle.docxA large bullfrog hops onto a prime spot on log and shoves off a turtle.docx
A large bullfrog hops onto a prime spot on log and shoves off a turtle.docx
 
Passengers arrive at the taxi stand at a Poisson rate of 2 per minute.docx
Passengers arrive at the taxi stand at a Poisson rate of 2 per minute.docxPassengers arrive at the taxi stand at a Poisson rate of 2 per minute.docx
Passengers arrive at the taxi stand at a Poisson rate of 2 per minute.docx
 
Pattern recognition is one of the core tasks in data mining- Direction.docx
Pattern recognition is one of the core tasks in data mining- Direction.docxPattern recognition is one of the core tasks in data mining- Direction.docx
Pattern recognition is one of the core tasks in data mining- Direction.docx
 
Pathogenesis of yersinia bacteria- And Virulence factors of yersinia.docx
Pathogenesis of yersinia bacteria- And  Virulence factors of yersinia.docxPathogenesis of yersinia bacteria- And  Virulence factors of yersinia.docx
Pathogenesis of yersinia bacteria- And Virulence factors of yersinia.docx
 
Pareto Efficiency- clearly provide the following- (1) establish the re.docx
Pareto Efficiency- clearly provide the following- (1) establish the re.docxPareto Efficiency- clearly provide the following- (1) establish the re.docx
Pareto Efficiency- clearly provide the following- (1) establish the re.docx
 
Part - Pleace indinate hnu ie the trancartinn afferte the arcnuntinn.docx
Part  - Pleace indinate hnu ie the trancartinn afferte the arcnuntinn.docxPart  - Pleace indinate hnu ie the trancartinn afferte the arcnuntinn.docx
Part - Pleace indinate hnu ie the trancartinn afferte the arcnuntinn.docx
 
P90- lbps (Type an integer or a decimal- Do not round-).docx
P90- lbps (Type an integer or a decimal- Do not round-).docxP90- lbps (Type an integer or a decimal- Do not round-).docx
P90- lbps (Type an integer or a decimal- Do not round-).docx
 
p2+2pq+q2-1Q4- In a population that is in Hardy-Weinberg equilibrium-.docx
p2+2pq+q2-1Q4- In a population that is in Hardy-Weinberg equilibrium-.docxp2+2pq+q2-1Q4- In a population that is in Hardy-Weinberg equilibrium-.docx
p2+2pq+q2-1Q4- In a population that is in Hardy-Weinberg equilibrium-.docx
 
P(X-17)-n-20-p-0-9.docx
P(X-17)-n-20-p-0-9.docxP(X-17)-n-20-p-0-9.docx
P(X-17)-n-20-p-0-9.docx
 
P(A)-0-5-P(B)-0-6-P(AB)-0-4- Find P(A union B) a- 0-7 b- 0-6 c- 0-86 d.docx
P(A)-0-5-P(B)-0-6-P(AB)-0-4- Find P(A union B) a- 0-7 b- 0-6 c- 0-86 d.docxP(A)-0-5-P(B)-0-6-P(AB)-0-4- Find P(A union B) a- 0-7 b- 0-6 c- 0-86 d.docx
P(A)-0-5-P(B)-0-6-P(AB)-0-4- Find P(A union B) a- 0-7 b- 0-6 c- 0-86 d.docx
 
Over the past few decades of warming- most biological organisms have a.docx
Over the past few decades of warming- most biological organisms have a.docxOver the past few decades of warming- most biological organisms have a.docx
Over the past few decades of warming- most biological organisms have a.docx
 
OVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docx
OVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docxOVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docx
OVERVIEW- In 2001- Troy Stubblefield- the owner of Shreveport Air Tool.docx
 
Out of Trait- behavioural- relational and contingency approaches of le.docx
Out of Trait- behavioural- relational and contingency approaches of le.docxOut of Trait- behavioural- relational and contingency approaches of le.docx
Out of Trait- behavioural- relational and contingency approaches of le.docx
 
Output of electron transport chain (2-2).docx
Output of electron transport chain (2-2).docxOutput of electron transport chain (2-2).docx
Output of electron transport chain (2-2).docx
 
Overview Dagnostic coding and reporting guidelines for outpatient serv.docx
Overview Dagnostic coding and reporting guidelines for outpatient serv.docxOverview Dagnostic coding and reporting guidelines for outpatient serv.docx
Overview Dagnostic coding and reporting guidelines for outpatient serv.docx
 
out of Stanford University and founded the blood testing company clini.docx
out of Stanford University and founded the blood testing company clini.docxout of Stanford University and founded the blood testing company clini.docx
out of Stanford University and founded the blood testing company clini.docx
 
Otosclerosis (abnormal bone growth) of the stapes would cause what kin.docx
Otosclerosis (abnormal bone growth) of the stapes would cause what kin.docxOtosclerosis (abnormal bone growth) of the stapes would cause what kin.docx
Otosclerosis (abnormal bone growth) of the stapes would cause what kin.docx
 
Oriole Corporation has outstanding 19-000 shares of $5 par value commo.docx
Oriole Corporation has outstanding 19-000 shares of $5 par value commo.docxOriole Corporation has outstanding 19-000 shares of $5 par value commo.docx
Oriole Corporation has outstanding 19-000 shares of $5 par value commo.docx
 
Oriole Marine Products began the year with 10 units of marine floats a.docx
Oriole Marine Products began the year with 10 units of marine floats a.docxOriole Marine Products began the year with 10 units of marine floats a.docx
Oriole Marine Products began the year with 10 units of marine floats a.docx
 
Organizations use corporate strategy to select target domains- O.docx
Organizations use corporate strategy to select target domains-      O.docxOrganizations use corporate strategy to select target domains-      O.docx
Organizations use corporate strategy to select target domains- O.docx
 

Recently uploaded

Recently uploaded (20)

Morse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptxMorse OER Some Benefits and Challenges.pptx
Morse OER Some Benefits and Challenges.pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptxJose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
Jose-Rizal-and-Philippine-Nationalism-National-Symbol-2.pptx
 
Benefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational ResourcesBenefits and Challenges of Using Open Educational Resources
Benefits and Challenges of Using Open Educational Resources
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
The Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. HenryThe Last Leaf, a short story by O. Henry
The Last Leaf, a short story by O. Henry
 
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
Operations Management - Book1.p  - Dr. Abdulfatah A. SalemOperations Management - Book1.p  - Dr. Abdulfatah A. Salem
Operations Management - Book1.p - Dr. Abdulfatah A. Salem
 
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
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 

Note- Can someone help me with the private E get(int index- int curren (1).docx

  • 1. Note: Can someone help me with the private E get(int index, int currentIndex, Node n)method. The code is not running. Also I need help with the public void add(int index, E element) method too. Please use the parameters provided with the code to solve. package edu.ust.cisc; import java.util.Iterator; import java.util.NoSuchElementException; public class CiscSortedLinkedList > implements CiscList { /** * A reference to this list's dummy node. Its next reference should refer to the node containing the first element * in this list, or it should refer to itself if the list is empty. The next reference within the node containing * the last element in this list should refer to dummy, thus creating a cyclic list. */ private Node dummy; /** * Number of elements in the list. */ private int size; /** * Constructs an empty CiscSortedLinkedList instance with a non-null dummy node whose next reference refers to * itself. */ public CiscSortedLinkedList() { dummy = new Node<>(null, null); dummy.next = dummy; } /** * Returns the number of elements in this list. * * @return the number of elements in this list */ @Override public int size() { return size; } /** * Returns {@code true} if this list contains no elements. * * @return {@code true} if this list contains no elements */ @Override public boolean isEmpty() { return size==0; } /** * Returns {@code true} if this list contains the specified element (compared using the {@code equals} method). * This implementation should stop searching as soon as it is able to determine that the specified element is not * present. * * @param o element whose presence in this list is to be tested * @return {@code true} if this list contains the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean contains(Object o) { if(o==null){ throw new NullPointerException(); } return containsHelper(o,dummy.next); } private boolean containsHelper(Object o, Node node){ if(node== dummy){ return false; } else if(o.equals(node.data)){ return true; } else{ return containsHelper(o,node.next); } } /** * Returns an iterator over the elements in this list in proper sequence. * * @return an iterator over the elements in this list in proper sequence */ @Override public Iterator iterator() { //return new Iterator (){ //private Node curr = dummy.next; //private Node prev = dummy; //private boolean canRemove = false; return null; } /** * Returns an array containing all of the elements in this list in proper sequence (from first to last element). * The returned array will be "safe" in that no references to it are maintained by this list. (In other words, * this method must allocate a new array even if this list is backed by an array). The caller is thus free to modify * the returned array. * * @return an array containing all of the elements in this list in proper sequence */ @Override public Object[] toArray() { Object[] arr = new Object[size]; int i = 0; for(Node current = dummy;current!=null;current= current.next){ arr[i++] = current.data; } return arr; } /** * {@link #toArray} recursive helper method. Adds the element contained in the specified node to the specified index * in the specified array. Recursion stops when the specified node is the dummy node. * * @param arr the array into which each element in this list should be added * @param index the index into which the next element in this list should be added * @param n the node containing the next element in this list to add to the array */ private void toArray(Object[] arr, int index, Node n) { } /** * Adds the specified element to its sorted location in this list. * * Lists may place the specified element at arbitrary locations if desired. In particular, an ordered list will * insert the specified element at its sorted location. List classes should clearly specify in their documentation * how elements will be added to the list if different from the default behavior (end of this list). * * @param value element to be added to this list * @return {@code true} * @throws NullPointerException if the specified element is null */ @Override public
  • 2. boolean add(E value) { return false; } /** * {@link #add} recursive helper method. Adds the specified value to the list in a new node following the specified * node (if that is the appropriate location in the list). * * @param value element to be added to this list * @param n a reference to the node possibly prior to the one created by this method */ private void add(E value, Node n) { } /** * Removes the first occurrence of the specified element from this list, if it is present. If this list does not * contain the element, it is unchanged. Returns {@code true} if this list contained the specified element. This * implementation should stop searching as soon as it is able to determine that the specified element is not * present. * * @param o element to be removed from this list, if present * @return {@code true} if this list contained the specified element * @throws NullPointerException if the specified element is null */ @Override public boolean remove(Object o) { if(o==null){ throw new NullPointerException(); } Node curr = dummy.next; Node prev = dummy; while (curr != dummy && !o.equals(curr.data)) { prev = curr; curr = curr.next; } if (curr == dummy) { return false; } else { System.out.println("Removing Data:"+curr.data); prev.next = curr.next; size--; return true; } } /** * {@link #remove} recursive helper method. Removes the node following n if it contains the specified element. This * implementation should stop searching as soon as it is able to determine that the specified element is not * present. * * @param o element to be removed from this list, if present * @param n a reference to the node prior to the one possibly containing the value to remove * @return */ private boolean remove(Object o, Node n) { return false; } /** * Removes all of the elements from this list. The list will be empty after this call returns. @Override public void clear() { dummy.next=dummy; size=0; } /** * Returns the element at the specified position in this list. * * @param index index of the element to return * @return the element at the specified position in this list * @throws IndexOutOfBoundsException if the index is out of range */ @Override public E get(int index) { if(index<0 || index>=size){ throw new IndexOutOfBoundsException(); } Node curr = dummy.next; for(int i=0;i n) { if(index<0 || index>=size){ throw new IndexOutOfBoundsException(); } Node curr = head; for(int i=0;i next_curr=curr.next; curr.next=n; while(n.next) { n = n.next; //finding end of n headed linked list n.next = next_curr;//adding rest linked list at end of n headed linked list } if(index==0) { return n; } else { return head; } } /** * * @param index index of the element to replace * @param element element to be stored at the specified position * @return the element previously at the specified position * @throws UnsupportedOperationException if the {@code set} operation is not supported by this list */ @Override public E set(int index, E element) { throw new UnsupportedOperationException(); } /** * This operation is not supported by CiscSortedLinkedList. * * @param index index at which the specified element is to be inserted * @param element element to be inserted * @throws UnsupportedOperationException if the {@code set} operation is not supported by this list */ @Override public void add(int index, E element) { } /** * Appends all elements in the specified list to the end of this list, in the order that they are returned by the * specified list's iterator. * * @param c list containing elements to be added to this list * @return {@code true} if this list changed as a result of the call * @throws NullPointerException if the specified list is null */ @Override public boolean addAll(CiscList extends E> c) { return false; } /** * Removes the element at the specified position in this list. Shifts any subsequent elements to the left * (subtracts one from their indices). Returns the element that was removed from the list. * * @param index the index of the element to be removed * @return the element previously at the specified position * @throws IndexOutOfBoundsException if the index is out of range */ @Override public E remove(int index) { return null; } /** * {@link #remove} recursive helper method. Removes the node
  • 3. following n if it contains the element at the specified * index. * * @param index the index of the element to be removed * @param currentIndex the index of the node parameter * @param n the node containing the element at currentIndex * @return */ private E remove(int index, int currentIndex, Node n) { return null; } /** * Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not * contain the element (compared using the {@code equals} method). This implementation should stop searching as * soon as it is able to determine that the specified element is not present. * @param o element to search for * @return the index of the first occurrence of the specified element in this list, or -1 if this list does not * contain the element * @throws NullPointerException if the specified element is null */ @Override public int indexOf(Object o) { if(o==null){ throw new NullPointerException(); } return indexOf(o,0, dummy.next); } /** * {@link #indexOf} recursive helper method. Returns currentIndex if the element contained in the node parameter is * equal to the specified element to search for. This implementation should stop searching as soon as it is able to * determine that the specified element is not present. * * @param o element to search for * @param currentIndex the index of the node parameter * @param n the node containing the element at currentIndex * @return the index of the first occurrence of the specified element in this list, or -1 if this list does not * contain the element */ private int indexOf(Object o, int currentIndex, Node n) { if(n.data.equals(o)){ return currentIndex; } else if(n==dummy){ return -1; } else if(n.data.compareTo((E)o)>0){ return -1; } else{ return indexOf(o,currentIndex+1,n.next); } } /** * Returns a string representation of this list. This string should consist of a comma separated list of values * contained in this list, in order, surrounded by square brackets (examples: [3, 6, 7] and []). * * @return a string representation of this list */ public String toString() { return null; } /** * {@link #toString} recursive helper method. Returns a string representation of this list, beginning with the * element in the specified node * * @param n the node containing the next element to append to the string * @return a string representation of this list, beginning with the element in the specified node */ private String toString(Node n) { return null; } private static class Node { private E data; private Node next; private Node(E data, Node next) { this.data = data; this.next = next; } } private class CiscLinkedListIterator implements Iterator { /** * A reference to the node containing the next element to return, or to the dummy node if there are no more * elements to return. */ private Node nextNode; /** * Constructs an iterator ready to return the first element in the list (if present). */ public CiscLinkedListIterator() { } /** * Returns {@code true} if the iteration has more elements. (In other words, returns {@code true} if * {@link #next} would return an element rather than throwing an exception.) * * @return {@code true} if the iteration has more elements */ @Override public boolean hasNext() { return false; } /** * Returns the next element in the iteration. * * @return the next element in the iteration * @throws NoSuchElementException if the iteration has no more elements */ @Override public E next() { return null; } } }