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.
Problem Statement: Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Example…
Given an integer A. Compute and return the square root of A. If A is…
Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…
A heap is a specialized tree-based data structure that satisfies the heap property. It is…
What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…
View Comments
Well explained article