Queue is not correctly implemented

2
closed
Robertoskr
Robertoskr
Posted 1 year ago

Queue is not correctly implemented #266

Hello, maybe im wrong, (im new to rust) but seeing the queue code, the dequeue operation is taking O(n) time, and its suposed to take O(1) time.

I assume that the vector is implemented like in other languages (e.g c++) and a vector is really a dynamic array, and remove the first take O(n) because you need to swap all the elements one position to the left.

If this assumption is false, then ignore this comment.

siriak
siriak
Created 1 year ago

@Robertoskr thanks for reporting! @imp2002 could you look into that?

imp2002
imp2002
Created 1 year ago

Yes, it's O(n). Because it's implment with Vec, remove the first elem then all the elements remained one position to the left. If expect O(1), use LinkList to impl.