A singly linked list, in its simplest form, is a collection of nodes that collectively form a linear sequence.
Each node stores a reference to an object that is an element of the sequence, as well as a reference to the next node of the list.
The list instance maintains a member named head that identifies the first node of the list.
In some applications another member named tail that identifies the last node of the list.
The first and last node of a linked list are known as the head and tail of the list.
We can identify the tail as the node having None as its next reference.
This process is commonly known as traversing the linked list.
Because the next reference of a node can be viewed as a link or pointer to another node, the process of traversing a list is also known as link hopping or pointer hopping.
Singly LinnkedList Note the change of the diagram for simplicity.
An important property of a linked list is that it does not have a predetermined fixed size.
It uses space proportionally to its current number of elements.
To insert a new element at the head of the list:
We can also easily insert an element at the tail of the list, provided we keep a reference to the tail node
Note that we must set the next link of the tail in (b) before we assign the tail variable to point to the new node in (c).
Removing an element from the head of a singly linked list is essentially the reverse operation of inserting a new element at the head.
If you like my post please follow me to read my latest post on programming and technology.
Find the length of the longest absolute path to a file within the abstracted file…
You manage an e-commerce website and need to keep track of the last N order…
You are given a stream of elements that is too large to fit into memory.…
The formula for the area of a circle is given by ฯrยฒ. Use the Monte…
Given an integer k and a string s, write a function to determine the length…
There is a staircase with N steps, and you can ascend either 1 step or…
View Comments
Well explained article