Queue is not correctly implemented
Robertoskr opened this issue · 2 comments
Robertoskr commented
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 commented
@Robertoskr thanks for reporting! @imp2002 could you look into that?
imp2002 commented
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.