Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

Stacks

A stack is a data structure where data items are always added and removed from the top. It is often referred to as a ‘last in, first out’ data structure.

Stacks

Stacks

  • A stack is a data structure where data items are always added and removed from the top. It is often referred to as a ‘last in, first out’ data structure.
  • Stacks can be implemented using other data structures, such as arrays or linked lists. In either case, an extra variable is required to identify the top of the stack.
Stack operations

Stack operations

  • Several operations can be carried out on stacks:
    • push() - adds an item to the top of a stack.
    • pop() - removes and displays the item at the top of a stack
    • peek() - displays the item at the top of a stack without removing it
    • isEmpty() - checks to see if the stack is empty
    • isFull() - checks to see if the stack is full
Uses

Uses

  • The most common use of stacks is to reverse the order of a set of data items, as they are ‘popped’ in the opposite order that they were ‘pushed’ to a stack.
  • They are also used by processors to handle interrupts.
  • Stacks can be ‘static’ (fixed in size) or ‘dynamic’ (able to grow in size as necessary)
Errors

Errors

  • Stack overflow errors can occur in static stacks when attempting to push an item onto a stack that is full.
  • Similarly, when trying to pop from an empty stack a stack underflow error occurs.
Jump to other topics
1

Components of a Computer

2

Software & Software Development

3

Exchanging Data

4

Data Types, Data Structures & Algorithms

5

Legal, Moral, Cultural & Ethical Issues

6

Elements of Computational Thinking

6.1

Thinking Abstractly

6.2

Thinking Ahead

6.3

Thinking Procedurally

6.4

Thinking Logically

6.5

Thinking Concurrently

7

Problem Solving & Programming

8

Algorithms

Practice questions on Stacks

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
    Stack operations:Fill in the list
  2. 2
Answer all questions on Stacks

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium