A linked list is a dynamic data structure that stores data elements in a group of any storage unit (continuous or discontinuous.
Each element in the linked list becomes a "Node", and each node is composed of a data field and a pointer field. The pointer field in each node points to the next node. Head is the "head Pointer", indicating the start of the linked list. It is used to point to the first node. the pointer field of the last pointer is null (empty address), indicating the end of the linked list.
It can be seen that the linked list structure can only be achieved through pointers, that is, a node must contain a pointer variable to store the address of the next node.
In fact, each node in the linked list can use several data and several pointers. The linked list with only one pointer in the node is called a single-chain table, which is the simplest chain table structure.
// Test1.cpp: defines the entry point for the console application <SPAN class = 'wp _ keywordlink '> Program </span>. <Br/> // </P> <p> # include "stdafx. H "<br/> # include <iostream> <br/> using namespace STD; </P> <p> typedef struct node <br/> {<br/> int data; <br/> struct node * Next; <br/>} node; </P> <p> void creatlist (node * & L) <br/> {<br/> node * s; <br/> int I; <br/> L = (node *) malloc (sizeof (node); <br/> L-> next = NULL; </P> <p> int N; <br/> cout <"Enter the number of nodes:" <Endl; <br/> CIN> N; <br/> cout <"Enter node data: "<Endl; <br/> for (I = 0; I <n; I ++) <Br/>{< br/> S = (node *) malloc (sizeof (node); <br/> int A; <br/> CIN>; <br/> S-> DATA = A; <br/> S-> next = L-> next; <br/> L-> next = s; <br/>}</P> <p >}< br/> void displaylist (node * l) <br/>{< br/> cout <"output: "<Endl; <br/> node * q; <br/> q = L-> next; <br/> for (; Q! = NULL; q = Q-> next) <br/>{< br/> cout <q-> data; <br/> cout <''; <br/> cout <Endl; </P> <p >}< br/> void main () <br/>{< br/> node * P; </P> <p> creatlist (p); <br/> displaylist (P ); </P> <p >}</P> <p>