What are the differences between a stack and a queue?

Both the stack and the queue are data structures, i.e. ways of storing data. It is important to know the differences between how these two data structures operate so that you know when to use one or the other. 

A stack works exactly as a stack of books, the one you usually have on your desk, for some visualisation. A stack operates on the LIFO principle (Last In First out). For example, if you want to add a book to your stack, you would (naturally) place it on top of all others. This book you just added is the Last one In. To get to books which are underneath this one, you would have to "pop" this Last book out. So, the Last one In is the First one Out.

With a queue, it is completely different. It operates, just as the name suggests, like a queue in a store, by the FIFO principle: First In First Out. For a queue to move, you can only "dequeue" (i.e. eliminate) items in the exact order that they were added. Otherwise it wouldn't be much of a queue, would it now? So the first customer, for example, is the First one In. A second customer appears, and it gets stored right behind the First one. We have to deal with the First customer in order for us to get to the ones follwing it. So the First one In is the First one Out.

Answered by Ecaterina D. Computing tutor

1707 Views

See similar Computing GCSE tutors

Related Computing GCSE answers

All answers ▸

What is an Algorithm?


Describe how sensors and microprocessors are used to maintain certain conditions.


why don't we all program in high level languages all the time if they are so much easier?


Convert 'A1' hexadecimal value into binary.


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo
Cookie Preferences