Блог пользователя white_horseman

Автор white_horseman, 5 лет назад, По-английски

C++ STL support all of the three data structures. Stack offers LIFO type operation, and queue offers FIFO type operation. But on the other hand, deque gives user the flexibility to add/remove elements from both it's end — front and back. Thereby deque can mimic the operations of both stack and queue if required. But there is more to it...

I conducted the tests on all three of them to test their performance by using a simple code that inserted 50000000 elements into the data structure then popped all out one by one. I found out that deque is roughly 10% faster than both stack and queue which can be understood from the fact that deque is the underlying container for both stack and queue which can be seen here as mentioned in comments. Also, deque supports range-based for loop iteration, which is unavailable for stack and queue(both of them require to create temporary copy for iteration). Thereby deque supports all operations much more faster than both stack and queue. So why not use dequeue instead of stack and queue ;)

Полный текст и комментарии »

  • Проголосовать: нравится
  • +26
  • Проголосовать: не нравится