Simple linked list
Simple linked list

Simple linked list



You work for a music streaming company.

You've been tasked with creating a playlist feature for your music player application.


Write a prototype of the music player application.

For the prototype, each song will simply be represented by a number. Given a range of numbers (the song IDs), create a singly linked list.

Given a singly linked list, you should be able to reverse the list to play the songs in the opposite order.


The linked list is a fundamental data structure in computer science, often used in the implementation of other data structures.

The simplest kind of linked list is a singly linked list. That means that each element (or "node") contains data, along with something that points to the next node in the list.

If you want to dig deeper into linked lists, check out this article that explains it using nice drawings.

Implementation Hints

We have provided the general structure of a List class for you. It has the private variables head of type Element* and current_size of type size_t that you can use.

The Element struct was given as well, it has two variables: data of type int and next of type Element*.

You can see the details in simple_linked_list.h. You do not have to change that file, but you can if it fits your needs.

The tests use the functions as they are supplied in simple_linked_list.cpp, don't change their signature. You can add more functions and members if you want to.

Can I use smart pointers?

Although the header-file includes raw pointers, you are free to chose a different implementation.

Last updated 31 May 2023
Edit via GitHub The link opens in a new window or tab
C++ Exercism

Ready to start Simple linked list?

Sign up to Exercism to learn and master C++ with 60 exercises, and real human mentoring, all for free.