I have to implement a queue by using circular linked lists with only one iterator. My doubt is which is the better way in terms of performance, maintaining an iterator to the first item or from the last item?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, if you have a pointer to the first item, then operations on the end of the list are going to be O(N). With a pointer to the end of the list, you can do operations on both the beginning and the end in O(1). Generally, if you have a circularly linked list, then you want to be able to reach the beginning and the end, so the answer is that you performance will be better with a pointer to the end.