Course of Raku / Addendum 🆕 / Types and text machines / Objects and classes / Exercises

A stack class

Problem

Write a Stack class with methods to push a value, pop the top value, peek at the top without removing it, and report its size. Push 1, 2, 3, then print the result of peeking, popping, and asking for the size.

Example

The program prints:

3
3
2

Solution

See the solution

Course navigation

Objects and classes   |   Solution: A stack class