exercism-cpp / simple-linked-list /
@Wook Song Wook Song authored on 15 Sep 2023
..
.exercism Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
test Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
CMakeLists.txt Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
HELP.md Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
README.md Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
simple_linked_list.cpp Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
simple_linked_list.h Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
simple_linked_list_test.cpp Medium: Add solution for "nth-prime", "sieve", and "simple-linked-list" 2 years ago
README.md

Simple linked list

Welcome to Simple linked list on Exercism's C++ Track. If you need help running the tests or submitting your code, check out HELP.md.

Introduction

You work for a music streaming company.

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

Instructions

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][intro-linked-list] that explains it using nice drawings.

[intro-linked-list]: https://medium.com/basecs/whats-a-linked-list-anyway-part-1-d8b7e6508b9d

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 choose a different implementation.

Source

Created by

  • @vaeng

Based on

Inspired by 'Data Structures and Algorithms with Object-Oriented Design Patterns in Ruby', singly linked-lists. - https://web.archive.org/web/20160731005714/http://brpreiss.com/books/opus8/html/page96.html