C++ tutorial-define element of linked list

C++ Structure example: building a singly linked list

Step 1: Define element of the linked list

The singly linked list element has two parts--data and pointer or link. Therefore, we define the the element of the linked list by using a structure that has two members--data and next pointer.

C single linked list

//C++ code to define element of singly linkedlist

struct ListElem{

  int data; // the element data
  ListElem *next; // next link


  //pfirst and plast pointers

  ListElem *pfirst;
  ListElem *plast;


This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.