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

1358 Views

See similar Computing GCSE tutors

Related Computing GCSE answers

All answers ▸

How would you represent the decimal number 143 in 7 bit binary?


What is the difference between a high- and a low-level programming languages?


Why are certain fields chosen to be the primary key in a database?


Which of the following are usually found on the Central Processing Unit(CPU) of a personal computer?


We're here to help

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

© MyTutorWeb Ltd 2013–2024

Terms & Conditions|Privacy Policy