Q:

What are the differences between stacks and queues?

A:

Quick Answer

Queues process information in the order it is received, while stacks process the last item added first. Both methods are useful for different tasks, and knowing which process to use depends on what the goal is.

Continue Reading

Full Answer

A queue operates much like a queue in real life. The first to arrive are dealt with first. Queues are appropriate for handling many types of network requests; older requests for information should generally be dealt with first to prevent people from waiting indefinitely when new traffic comes. The term FIFO, which stands for "first in, first out," is common when discussing queues.

Stacks process the most recent requests first. When dealing with complex arithmetic problems, stacks tell the program to solve what is inside of parenthesis before proceeding. Stacks are also useful for initializing programs. Stacks operate on the LIFO, or "last in, first out," methodology.

Knowing which type of list to use is important for writing efficient programs, and some types of program logic only work with either stacks or queues. When using low-level programming languages, implementing a stack or queue typically requires dealing with arrays and pointers. High-level languages make the process simpler, and many provide efficient wrappers to simplify the process. Understanding how stacks and queues process information, however, is important to know regardless of which type of programming language is being used.

Learn more about Computer Programming

Related Questions

Explore