Looking at some of the algorithms on the network, I found an interesting one:
How to implement FIFO using LIFO?
I tried myself, but I had only one solution: every time we need a front FIFO element, copy lifo to another lifo ( excluding the last element, which is the front), get the front element and delete it, and then copy the second LIFO to first LIFO.
But this, of course, is terribly slow, it does a simple loop like this:
for(!myfifo.empty()) { myfifo.pop(); }
O (n²) instead of O (n) with the standard FIFO implementation.
Of course, LIFOs don’t do FIFOs, and we certainly won’t have the same difficulty using native FIFOs and fake LIFOs based FIFOs, but I think there is definitely a way to do better than O ( n²). Does anyone know about this?
Thanks in advance.
algorithm fifo
Undo
source share