SlideShare a Scribd company logo
1 of 3
Download to read offline
I am failing a few tests with my Double Linked List program. Can someone show me the
following methods for doubly linked lists? (In Java)
public void addAfter(Object element, Object target)
public int indexOf(Object element)
public void add(int index, Object element)
public boolean contains(Object target)
Thanks!
Solution
public class DoubleLinkedList {
class Node{
Node next;
Node prev;
Object val;
Node(){
next = null;
prev = null;
val = null;
}
}
Node start = null;
public DoubleLinkedList() {
super();
this.start = null;
}
public void addAfter(Object element, Object target){
Node t = this.start;
while(!t.val.equals(target) && t != null){
t = t.next;
}
if(t == null) System.out.println("Target not found");
else{
Node temp = t;
Node n = new Node();
n.val = element;
n.prev = temp;
n.next = temp.next;
temp.next.prev = n;
temp.next = n;
}
}
public int indexOf(Object element){
int i = 0;
Node t = start;
while(t!=null){
i++;
if(!t.val.equals(element)) t = t.next;
else break;
}
if(t!=null) return i;
else return -1;
//return i;
}
public void add(int index, Object element){
//assume index starts from 1
Node t = start;
int i = 0;
if(index == 1)
{
Node n = new Node();
n.prev = null;
n.val = element;
n.next = start;
start.prev = n;
start = n;
} else {
while(i

More Related Content

Similar to I am failing a few tests with my Double Linked List program. Can som.pdf

Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional ProgrammingEelco Visser
 
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
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdfUsing visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdfacteleshoppe
 
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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfarchgeetsenterprises
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfNicholasflqStewartl
 
Intro to Java Programming 10th ed- Implement the inorder- preorder- po.docx
Intro to Java Programming 10th ed- Implement the inorder- preorder- po.docxIntro to Java Programming 10th ed- Implement the inorder- preorder- po.docx
Intro to Java Programming 10th ed- Implement the inorder- preorder- po.docxolsenlinnea427
 
Create your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdfCreate your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdfarumugambags
 
Write a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdfWrite a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdfinfo785431
 
Can someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdfCan someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdfABHISHEKREADYMADESKO
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfaamousnowov
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfallurafashions98
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfanjanacottonmills
 
This is a homework assignment that has to be done in JAVA.Objectiv.pdf
This is a homework assignment that has to be done in JAVA.Objectiv.pdfThis is a homework assignment that has to be done in JAVA.Objectiv.pdf
This is a homework assignment that has to be done in JAVA.Objectiv.pdffeelingcomputors
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfmohamednihalshahru
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfamrishinda
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfarchiesgallery
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfjyothimuppasani1
 
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.pdfmail931892
 
[NHN NEXT] Java 강의 - Week2
[NHN NEXT] Java 강의 - Week2[NHN NEXT] Java 강의 - Week2
[NHN NEXT] Java 강의 - Week2Young-Ho Cho
 

Similar to I am failing a few tests with my Double Linked List program. Can som.pdf (20)

Lecture 5: Functional Programming
Lecture 5: Functional ProgrammingLecture 5: Functional Programming
Lecture 5: Functional Programming
 
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
 
Using visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.pdfUsing visual studio 2022- a C# windows form application- and your Doub.pdf
Using visual studio 2022- a C# windows form application- and your Doub.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
 
hi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdfhi i have to write a java program involving link lists. i have a pro.pdf
hi i have to write a java program involving link lists. i have a pro.pdf
 
Having a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdfHaving a problem figuring out where my errors are- The code is not run.pdf
Having a problem figuring out where my errors are- The code is not run.pdf
 
Intro to Java Programming 10th ed- Implement the inorder- preorder- po.docx
Intro to Java Programming 10th ed- Implement the inorder- preorder- po.docxIntro to Java Programming 10th ed- Implement the inorder- preorder- po.docx
Intro to Java Programming 10th ed- Implement the inorder- preorder- po.docx
 
Create your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdfCreate your own Linked list from scratch (singly linked list).So.pdf
Create your own Linked list from scratch (singly linked list).So.pdf
 
Write a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdfWrite a JAVA LinkedListRec class that has the following methods siz.pdf
Write a JAVA LinkedListRec class that has the following methods siz.pdf
 
Can someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdfCan someone help me to fix the code please package dlist i.pdf
Can someone help me to fix the code please package dlist i.pdf
 
There are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdfThere are a couple of new methods that you will be writing for this pr.pdf
There are a couple of new methods that you will be writing for this pr.pdf
 
I need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdfI need help finishing this code in JavaYou will need to create t.pdf
I need help finishing this code in JavaYou will need to create t.pdf
 
NumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdfNumberList.java (implements the linked list)public class NumberLis.pdf
NumberList.java (implements the linked list)public class NumberLis.pdf
 
This is a homework assignment that has to be done in JAVA.Objectiv.pdf
This is a homework assignment that has to be done in JAVA.Objectiv.pdfThis is a homework assignment that has to be done in JAVA.Objectiv.pdf
This is a homework assignment that has to be done in JAVA.Objectiv.pdf
 
Create a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdfCreate a new java class called ListNode. Implement ListNode as a gen.pdf
Create a new java class called ListNode. Implement ListNode as a gen.pdf
 
JAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdfJAVA A double-ended queue is a list that allows the addition and.pdf
JAVA A double-ended queue is a list that allows the addition and.pdf
 
Need Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdfNeed Help with this Java Assignment. Program should be done in JAVA .pdf
Need Help with this Java Assignment. Program should be done in JAVA .pdf
 
Help please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.pdfHelp please!!(Include your modified DList.java source code file in.pdf
Help please!!(Include your modified DList.java source code file in.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
 
[NHN NEXT] Java 강의 - Week2
[NHN NEXT] Java 강의 - Week2[NHN NEXT] Java 강의 - Week2
[NHN NEXT] Java 강의 - Week2
 

More from PRATIKSINHA7304

Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfPRATIKSINHA7304
 
Find the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfFind the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfPRATIKSINHA7304
 
A new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfA new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfPRATIKSINHA7304
 
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfAre these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfPRATIKSINHA7304
 
1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdfPRATIKSINHA7304
 
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdfPRATIKSINHA7304
 
You are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfYou are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfPRATIKSINHA7304
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfPRATIKSINHA7304
 
Wiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfWiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfPRATIKSINHA7304
 
Which of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfWhich of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfPRATIKSINHA7304
 
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdfPRATIKSINHA7304
 
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfWhat are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfPRATIKSINHA7304
 
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfWhat led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfPRATIKSINHA7304
 
What is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfWhat is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfPRATIKSINHA7304
 
What factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfWhat factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfPRATIKSINHA7304
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfPRATIKSINHA7304
 
this is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfthis is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfPRATIKSINHA7304
 
This fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfThis fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfPRATIKSINHA7304
 
The term refers to a. Global Analysis of the proteins produced in .pdf
The term  refers to  a. Global Analysis of the proteins produced in .pdfThe term  refers to  a. Global Analysis of the proteins produced in .pdf
The term refers to a. Global Analysis of the proteins produced in .pdfPRATIKSINHA7304
 

More from PRATIKSINHA7304 (20)

Hi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdfHi, I need help with a java programming project. specifically practi.pdf
Hi, I need help with a java programming project. specifically practi.pdf
 
Find the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdfFind the sum of the infinite geometric series if it exists. (If an .pdf
Find the sum of the infinite geometric series if it exists. (If an .pdf
 
A new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdfA new class will be added to the startup package to start up the eve.pdf
A new class will be added to the startup package to start up the eve.pdf
 
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdfAre these statements regarding Rhizobacteria true Plant Growth P.pdf
Are these statements regarding Rhizobacteria true Plant Growth P.pdf
 
1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf1. Prices may be different between two countries whenA. Both count.pdf
1. Prices may be different between two countries whenA. Both count.pdf
 
[10 points]Add the.pdf
[10 points]Add the.pdf[10 points]Add the.pdf
[10 points]Add the.pdf
 
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
§ 7.3 7.6 Which member of the following pairs is likely to decompose .pdf
 
You are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdfYou are requested to write the SQL commands to perform the following.pdf
You are requested to write the SQL commands to perform the following.pdf
 
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdfwrite a prgoram that displays four images or objects in a 2 x 2 grid.pdf
write a prgoram that displays four images or objects in a 2 x 2 grid.pdf
 
Wiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdfWiater Company operates a small manufacturing facility. On January 1,.pdf
Wiater Company operates a small manufacturing facility. On January 1,.pdf
 
Which of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdfWhich of the three types of activities reported on the statement of c.pdf
Which of the three types of activities reported on the statement of c.pdf
 
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
111. Definition Explanation (15) 1. Job speciation SolutionIII.pdf
 
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdfWhat are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
What are the pros and cons of using exFAT and ReFS on a Windows 2012.pdf
 
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdfWhat led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
What led to the demise of ‘conventional Keynesian wisdom’ in the mid.pdf
 
What is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdfWhat is the connection between relative frequency and probability.pdf
What is the connection between relative frequency and probability.pdf
 
What factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdfWhat factors led President Truman to support the creation of Israel .pdf
What factors led President Truman to support the creation of Israel .pdf
 
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdfunixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
unixlinux - kernelexplain yield in user spaceexplain yield in k.pdf
 
this is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdfthis is java. problem.i already make employee class. but i can not.pdf
this is java. problem.i already make employee class. but i can not.pdf
 
This fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdfThis fall Millie finally repaid her student loan. She originally bor.pdf
This fall Millie finally repaid her student loan. She originally bor.pdf
 
The term refers to a. Global Analysis of the proteins produced in .pdf
The term  refers to  a. Global Analysis of the proteins produced in .pdfThe term  refers to  a. Global Analysis of the proteins produced in .pdf
The term refers to a. Global Analysis of the proteins produced in .pdf
 

Recently uploaded

Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint23600690
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....Ritu480198
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjMohammed Sikander
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi RajagopalEADTU
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital ManagementMBA Assignment Experts
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptxPoojaSen20
 

Recently uploaded (20)

Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Book Review of Run For Your Life Powerpoint
Book Review of Run For Your Life PowerpointBook Review of Run For Your Life Powerpoint
Book Review of Run For Your Life Powerpoint
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
e-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopale-Sealing at EADTU by Kamakshi Rajagopal
e-Sealing at EADTU by Kamakshi Rajagopal
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
MOOD STABLIZERS DRUGS.pptx
MOOD     STABLIZERS           DRUGS.pptxMOOD     STABLIZERS           DRUGS.pptx
MOOD STABLIZERS DRUGS.pptx
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 

I am failing a few tests with my Double Linked List program. Can som.pdf

  • 1. I am failing a few tests with my Double Linked List program. Can someone show me the following methods for doubly linked lists? (In Java) public void addAfter(Object element, Object target) public int indexOf(Object element) public void add(int index, Object element) public boolean contains(Object target) Thanks! Solution public class DoubleLinkedList { class Node{ Node next; Node prev; Object val; Node(){ next = null; prev = null; val = null; } } Node start = null; public DoubleLinkedList() { super(); this.start = null; } public void addAfter(Object element, Object target){ Node t = this.start;
  • 2. while(!t.val.equals(target) && t != null){ t = t.next; } if(t == null) System.out.println("Target not found"); else{ Node temp = t; Node n = new Node(); n.val = element; n.prev = temp; n.next = temp.next; temp.next.prev = n; temp.next = n; } } public int indexOf(Object element){ int i = 0; Node t = start; while(t!=null){ i++; if(!t.val.equals(element)) t = t.next; else break; } if(t!=null) return i; else return -1; //return i; } public void add(int index, Object element){
  • 3. //assume index starts from 1 Node t = start; int i = 0; if(index == 1) { Node n = new Node(); n.prev = null; n.val = element; n.next = start; start.prev = n; start = n; } else { while(i