posted 10 years ago
Greetings Mike,
First and mostly, please follow what Junilu suggested - it is really important that you understand the data structure before you implement it.
Next, (a really nice hint) if you understand the data structure,then create a null node as your head/tail pointer (i.e.: null data, next points to itself, prev points to itself). If you don’t understand this - don’t worry, just saving you edge case issues.
Understand that all (most) actions in a DLL are done via the current pointer location, so you may want to implement a few methods that manipulate the current pointer - like move next, move prev, move head, move tail, delete (or remove), insert after, note: now an insert prev can be a move prev, insert after.
All that said, there is some issue with the requirements as you said vs the code. Ok the data reference you are using is an int, but the delete seems to be the ‘index’ and not the contents. You need to resolve that.
So to sum up: you can write a few (bunch) of helper methods that you or may not expose to users of your main class that you can use to help you. Like: a print all could be:
moveToHead(), getSize(), while (size>0), getAtPointer(), print(), moveNext(), size— [end while]
Take some time to fully understand double linked lists - then (with pencil and paper) design your code, then and only then start coding.