C++C++11C++14C++17Learn C++

Learn To Code Simple Linked List In Modern C++ On Windows

What Is An Eligible Copy Constructor In C++ Software

Linked List, composed of structural elements and it is a linear data structure, and each element is stored at different memory locations. Linked lists are good to add, inserts, subtract, delete each element from this list. Linked lists were popular much in the 80s to 2000s, nowadays mostly vectors with structures are used instead of linked lists, because of their simplified operations. They are a little bit hard to code for beginners, but also they are still really good if you are strong on all linked list operations.

linked list element (generally a struct) is presented with a pointer while it’s each element are located in memory with calloc() or malloc() commands in their element size. These elements have at least one pointer of its another structure element ( generally called as *next) that points to another pointer (memory address).

In C++ Builder, you can use both linked list methods and vectors with CLANG C++17 standard compiler or with its New Bcc Compiler.

In this post we will present you a very simple linked list in Modern C++;

Let’s start with defining an element (st_user) structure of our linked list in a structure. This will be used to store user names, ages, and address of the next linked list.

Generally a linked lists is starts with a head pointer that shows the address of first member, and a current pointer (generally *p) is used to operate on a member, some linked lists may use a tail pointer to reach last element easily. Let’s define *head and *p;

Now we can allocate the first member in this user structure (st_user) and we can point it’s address with a head pointer as below;

As you see we allocate first member in memory with (struct st_user*) type, and this memory address is stored in *p. pointer. Now we can add a new member

Here head->next = p; means previous element’s *next address is address of new element. So we linked first element to second element. In this simple example we can write all elements of our linked list as below;

At the end we should free all linked list from the memory,

Full code of this C++ Builder Console VCL Application will be like this;

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

Learn Default Constructors Of Classes In Modern C++

Artificial Intelligence TechC++C++11C++14C++17Learn C++

How To Develop Special AI Activation Functions In C++?

Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?