Search code examples
javalinked-liststackqueuecomputer-science

When would you use a stack as opposed to a regular linked list or a regular queue as opposed to a priority queue in real life?


In my CS2 class, we are learning a lot of syntax for stacks, queues, and linked lists. Despite this, we haven't actually learned any applications of them or been told how to tell when we should use one data structure vs the other. Does anyone know of a resource to better understand differing applications of these varying data structures?


Solution

  • Stacks, queues, priority queues are very versatile data structures.

    You can find their uses in Competitive Programming, Processors, Operating Systems, and a lot more places I have not yet explored.

    As a Computer Science student, you will learn more about it in the future, when you take up courses like Computer Organization and OS.

    This answer explains the use of stacks in a microprocessor. A processor also uses Priority Queues to prioritize tasks, like handling of interrupts. Severe interrupts are given high priority, and mild interrupts are given less priority.

    Another use of the stack is in recording the trace-back for a software which just hit an exception (run-time usually). A python reference is attached here.

    According to me, these data structures don't need much practicing. You just need to know the crux of it. You should know what is the use of stack (Last In First Out), Queues, etc. However, priority queues are a bit more complex (in implementation), and you can always have a brush-up on it, if you want to implement it.