Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify add to pay attention to the value of previousORnext. If it is null, adding should easy. If it is not null, you have to

Modify "add" to pay attention to the value of previousORnext. If it is null, adding should easy. If it is not null, you have to do a comparison to determine if previousORnext is previous or next. Set previous or next to previousORnext and set next or previous using the getNext() or getPrevious method of DLLEntry.

Add newEntry to the list. Be careful: there are special cases if previous or next is null meaning it should be added first or last.

image text in transcribed

Default Code...

protected DLLEntry add (DLLEntry previousORnext, DLLEntry newEntry) { if(first == null) { first = newEntry; last = newEntry; } else { last.setNext(newEntry); newEntry.setPrevious(last); last = newEntry; }

return newEntry; }

My code, can my code be salvaged? or start from scratch?

protected DLLEntry add (DLLEntry previousORnext, DLLEntry newEntry) { if(first == null) { first = newEntry; last = newEntry; }

//start of my code

if(previousORnext != null) { newEntry.setNext(previousORnext); newEntry.setPrevious(previousORnext.getPrevious()); if(newEntry.getPrevious() != null) { newEntry.getPrevious().setNext(newEntry); } else if(previousORnext == first) { first.setPrevious(newEntry); newEntry.setNext(first); }

//end of my code

else { last.setNext(newEntry); newEntry.setPrevious(last); last = newEntry; } } return newEntry; }

location SortedDLLPD add(location, "Ian","271") entry first last Ian 271 Ann Bob Eve Zoe Jay 182 314 159 264 818 location SortedDLLPD add(location, "Ian","271") entry first last Ian 271 Ann Bob Eve Zoe Jay 182 314 159 264 818

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

8. Explain the relationship between communication and context.

Answered: 1 week ago