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

1674 Views

See similar Computing GCSE tutors

Related Computing GCSE answers

All answers ▸

State the denary representation of the binary number 10010111


Explain what is meant by "volatile" and "non-volatility" memory, their uses, and the difference between them


How would you check if a number is palindrome using a looping algorithm in any programming language ?


Write the number 195 in binary


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
Cookie Preferences