Introduction To Single Linked List
Description
- In a single-linked list every element contains some data and a link to the next element(link), which allows to keep the structure.
- In this type of Linked List two successive nodes are linked together in linear fashion.
- Each element of the list is called a “node”.
- First node is called “head” and it’s a dedicated node. By knowing it, we can access every other node in the list.
- Last node of the list is called “Tail”,By knowing it we can perform add operation.
- Each Node contain address of the next node to be followed.
- In Single Linked List only Linear or Forward Sequential movement(traversal) is possible.
- Elements are accessed sequentially, no direct access is allowed.
Structure of single linked list
- Every node of a singly-linked list contains following information
- A value (primitive data/user define data).
- A link to the next element (pointer data).
- Sketchy, it can be shown like this…
Example 1: primitive data type single lined list
struct single_link_list
{
int data;
struct slink*next;
};
Example 2: User define data type single lined list
struct emp
{
int id;
char name[36];
int sal;
};
struct single_link_list
{
struct emp data;
struct slink*next;
};
Single linked list Internal representation
- In Singly-linked list implementation First node called head and no other node points to it.
- Link to the head is usually stored its data and information of next data structure(Next link). For empty list, head initial value is set to “NULL”.
- in Single linked list Last node called “Tail” usually stored its data and Next link data value is set to “NULL” because it is terminal node.
- Below you can see another picture, which shows the whole singly-linked list internal representation..
Operations on Single Linked List
- Adding node
- Inserting node
- node Count
- Traversal
- Deletion node
- Updating node data
No comments:
Post a Comment