Yes, I know. I should have said "working with double linked lists (for deque) is easier than working with single linked lists (like for stack or queue)"
You can just... make a struct with "amount of elements in array" and "capacity" ints and a pointer to a memory region, it'll be faster than linked lists, a lot faster
This is how some libraries probably implement it by default. But in cases where memory efficiency is critical, the structure might get arbitrarily large, and/or the size of the of the structure may vary dramatically and non-monotonically over its lifetime, linked lists avoid overallocation and the intermittent performance hitches of reallocate-and-copy operations. Also, so long as you only ever need to do operations to the end, linked lists are simpler to implement and reason about (less chance of off-by one errors or other gotchas, and you don't need to wrap your head around amortization to see the O(1) time complexity for push/pop operations)
That mandatory Algorithms class in computer science programs is in part about being able to tell when you can and should deviate from the default way of doing things
View all comments
Show parent comment
2
u/pencilUserWho 11d ago
Yes, I know. I should have said "working with double linked lists (for deque) is easier than working with single linked lists (like for stack or queue)"
Sorry for the confusion