Key Concepts

Review core concepts you need to learn to master this subject

Stack overflow

Every stack has a size that determines how many nodes it can accommodate. Attempting to push a node in a full stack will result in a stack overflow. The program may crash due to a stack overflow.

A stack is illustrated in the given image. stackA.push(xg) will result in a stack overflow since the stack is already full.

Stacks: Swift
Lesson 1 of 1
  1. 1
    As you may recall, a stack is a linear data structure that contains an ordered set of data that follows a LIFO (last in, first out) protocol for accessing its data. A stack can be imagined as a…
  2. 2
    Stacks operate by making modifications just to the top, or head, of the stack. If we want to add a plate to our dish stack, we add it to the top of the pile. To add an item to the stack, we will …
  3. 3
    Once we’ve added nodes to a stack, we have the option to inspect the one on the top of the stack! As with the dishes example, you can only see the one at the top. We will be implementing this same …
  4. 4
    Now that we have items on our stack, and we know how to peek at the one on the top, we need to implement the removal of the topmost item off the stack. We’ll call this method, pop(). As shown in …
  5. 5
    Our Stack implementation is now complete. We can push, pop, and peek values on the Stack. As we know if we attempt too many pops eventually nil is returned as there are no Nodes on the stack. Howe…

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo