Hi, I am writing a Double linked list structure, and I have implemented a function called Insert which takes 2 params: The object and an int position.
It should add the object to the specified position. This all works fine, what I am wondering is if there is better way.
I set up my iterator and make it point to the beginning of the list. So, to insert at the position, what I do is use a for loop, that runs until the incrementing number is < position that was entered, moving my iterator forward each loop.
This of course, ends up as O(n) for large data. I know hashtable/array is better for this, But I would just like to know, is there any other way to insert at a specific position?