Hey guys ! I am trying to implement a list interface that allows fast modifications at the front back and middle. I tried using ArrayDeque however, was getting an efficiency error and, then used link but was again getting an efficiency error. Can someone please help me out and, let me know what is actually going on and, what am I doing wrong here. Here is my code.
First, welcome to the Ranch. We're glad you stopped by.
Next, it helps tremendously if you use "code tags". Before you past in your java, click the button labeled "Code" above. It will put in UBB tags that help format things, preserving indentation, and even doing context highlighting, making MUCH easier for us old timers to read it.
Finally, can you be more specific about your error? What is an "efficiency error"? I am not familiar with the term. Is it an error when you compile? When you run the code? something else? We find it much easier to help you if you TellTheDetails (<--that is a link). We LOVE to help, but your job is to make it as easy as possible for us to do so.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:I grabbed what you had above, and put it inside code tags. . . .
So did I, only on the original post. Let’s see whether we took out the same amount of blank space
Agree with Fred about efficiency errors. ArrayDeque ought to execute very quickly, so why are you creating your own List classes? What do you mean be fast modifications? What are you modifying and how fast do you want to do it?
What do you understand about the workings of a LinkedList? What do you understand about the workings of an arrayed list? Do you understand what sort of speed you can expect for
1: Adding at the end,
2: Adding in the middle,
3: Adding at the start,
4: Altering the capacity of the list,
5: Finding an element from its index,
6 7 8: Removing from end middle and beginning?
What is a Treque? Is it like a Deque with three ends? How does that work?
Why are you creating a List? If your class extends AbstractList<T>, it will implement the List<T> interface.
You need to answer all those questions, then you will know what you want. When you know what you actually want, you will be able to create it. But knowing what you want and why is a bigger part of the job than writing the code.
Tina Raja wrote:I mean that when I run the code its not fast enough.
Well....If you skim many of the posts in our "performance" forum, you'll see that "not fast enough" isn't really a valid issue.
Do you have specific, defined criteria for how fast it has to be (and what, exactly, is "it")? Can those speeds be justified somehow?
You are almost always better served by writing clean, simple, understandable code that you will be able to read in 6 months. If you are trying to change your code to save a microsecond on each iteration, then the operation would have to be performed a million times before you save ONE SECOND. Considering you are more likely to spend hours and hours debugging your code in the future, saving a second is probably not worth it.
So...having said all that...If you are trying to do something that lets you have random access (i.e. delete any element at any spot), perhaps a list is not the best data structure. Can you elaborate more on what the actual problem is you are trying to solve?