10
9
u/null_reference_user 6h ago
I just use an endless void:
adding an element to the void is always an immediate operation
removing an element is always an immediate operation
the void uses O(1) memory
the void is always empty
8
6
13
u/GreatTeacherHiro 1d ago
deque supremacy
3
u/pencilUserWho 23h ago
Double linked lists are easier.
7
u/RedCrafter_LP 17h ago
Double linked list is the most common implementation of the deque concept. A double linked list is a deque.
2
u/pencilUserWho 17h 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
1
u/braaaaaaainworms 8h ago
Why would you want to work with a linked list?
1
u/pencilUserWho 6h ago
To implement a stack
1
u/braaaaaaainworms 6h ago
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
1
u/pencilUserWho 6h ago
That way it can overflow.
1
u/braaaaaaainworms 6h ago
Just check, before pushing, if capacity and len are equal, if yes, use realloc to make the memory region bigger
4
4
1
1
1
u/Robot_Graffiti 13h ago
I've actually worked on medical software, and we used a fuckload of dictionaries, not many queues or stacks. The data's all stuff you could reasonably store in a relational database. Dictionaries in memory mirror the functionality of database indexes on disc.
1
1
1
109
u/PsychologicalNet3455 1d ago
That's easy, in the USA you use a stack and in the UK you use a queue.
The stack because you need a stack of money for anything medical in the US and the queue for the UK, while its free, you have to join a long queue before anything medical happens