Skip to main content
4 votes
Accepted

Are self-written queues and linked lists really worth it (better than built-in arrays)?

Will a proper dynamic data structure be more efficient than simulating it with fixed-size arrays? Almost certainly yes. But is it a good idea to build one for your project? This depends on many other ...
Kilian Foth's user avatar
4 votes
Accepted

How to properly delete nodes in a linked list?

Almost there! You have a linked list: HEAD ---> P ---> x ---> x ---> Q ---> TAIL You re-link part of the list (HEAD -> TAIL) to remove some nodes: HEAD ------------------------------...
amon's user avatar
  • 136k
4 votes
Accepted

How to store a branching linked list in a database

Two Tables A table of things, and a table of connections. Things := (Component ID | usefull stuff to know about the thing itself | etc) Connections := (Connection Type | From Component | From Port | ...
Kain0_0's user avatar
  • 16.6k
3 votes
Accepted

How to safely walk a list to remove an element as well as associated elements safely

The bug is caused by a (somewhat) complex interaction between: SLIST_FORACH_SAFE, and the recursive invocation of destroy_element, and the removal that they each do. SLIST_FOREACH_SAFE makes itself "...
Erik Eidt's user avatar
  • 34.8k
3 votes
Accepted

Linked-list iteration patterns

Caching effects are difficult to predict. In general, contiguous memory data structures like arrays of values are more cache friendly, but does this matter? Not for most code. For the purpose of ...
amon's user avatar
  • 136k
3 votes

Designing an efficient implementation of a random access queue based on a linkedlist

Sorry for the late answer but I think this will give O(1) insertion, removal and random access. Store the linked list nodes in a pre-allocated array. Addition involves adding the new node to the ...
George Godfrey's user avatar
2 votes

Converting binary tree into doubly linked circular list

The reason that multiple data structures exist is (and there isn't any one single data structure to rule them all) is because each data structure has different performance characteristics. It follows ...
Robert Harvey's user avatar
1 vote
Accepted

Inserting at head for a recursively defined linked list

The insert and __delitem__ methods of MutableSequence ABC are expected to do an in-place modification of the sequence you call them on. This means that code like this should work len(sequence) == 1 ...
Bart van Ingen Schenau's user avatar
1 vote

Why do we need stacks and queues?

Echoing @rwong comment, using a Queue or Stack Documents the contract Is a better name - might avoid the need for a comment Makes your intentions clear.
user949300's user avatar
  • 9,029

Only top scored, non community-wiki answers of a minimum length are eligible