Consider a singly linked list that has two members: mFirst, a pointer to the first element in the list, and mLast, a pointer to the last element in the list. The time of which of the following operations depends on the length of the list?
a) Delete the last element of the list.
b) Delete the first element of the list.
c) Add an element after the last element of the list.
d) Add an element before the first element of the list.
e) Interchange the first two elements of the list.
2 Comments so far
Leave a comment
a
By Stuart on 10.05.06 8:10 pm | Permalink
They can all be done in constant time if you keep a pointer to the head and tail of the list.
By Jeremy on 06.18.07 4:46 pm | Permalink
Leave a comment
If you are including code in your comment, place it within a <div class='code'></div> tag for better formatting.