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.

ED
Answered by Ecaterina D. Computing tutor

2137 Views

See similar Computing GCSE tutors

Related Computing GCSE answers

All answers ▸

What is Control Flow in a Computer Program?


Convert the following binary number into hexadecimal : 10111000


What are 'pointers'?


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 ustelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

MyTutor is part of the IXL family of brands:

© 2025 by IXL Learning