**1.SINGLY LINKED LIST**

All the nodes in a singly linked list are arranged sequentially
by linking with a

pointer. A singly linked list can grow or shrink, because it is
a dynamic data structure.

Following figure explains the different operations on a singly
linked list.

**Insertion Of new Node Algorithm:-**

**Insert a Node at the beginning**

1. Input DATA to be inserted

2. Create a NewNode

3. NewNode → DATA = DATA

4. If (SATRT equal to NULL)

(

*a*) NewNode → Link = NULL
5. Else

(

*a*) NewNode → Link = START
6. START = NewNode

7. Exit

**Insert a Node at the end**

1. Input DATA to be inserted

2. Create a NewNode

3. NewNode → DATA = DATA

4. NewNode → Next = NULL

8. If (SATRT equal to NULL)

(

*a*) START = NewNode
LINKED LIST 93

9. Else

(

*a*) TEMP = START
(

*b*) While (TEMP → Next not equal to NULL)
(

*i*) TEMP = TEMP → Next
10. TEMP → Next = NewNode

11. Exit

**Insert a Node at any specified position**

1. Input DATA and POS to be inserted

2. intialise TEMP = START; and j = 0

3. Repeat the step 3 while( k is less than POS)

(

*a*) TEMP = TEMP è Next
(

*b*) If (TEMP is equal to NULL)
(

*i*) Display “Node in the list less than the position”
(

*ii*) Exit
(

*c*)*k*=*k*+ 1
4. Create a New Node

5. NewNode → DATA = DATA

6. NewNode → Next = TEMP → Next

7. TEMP → Next = NewNode

8. Exit

### Deletion Of node:-

Suppose START is the first position in linked list. Let DATA be
the element to be

deleted. TEMP, HOLD is a temporary pointer to hold the node
address.

1. Input the DATA to be deleted

2. if ((START → DATA) is equal to DATA)

(

*a*) TEMP = START
(

*b*) START = START → Next
(

*c*) Set free the node TEMP, which is deleted
(

*d*) Exit
3. HOLD = START

4. while ((HOLD → Next → Next) not equal to NULL))

(

*a*) if ((HOLD → NEXT → DATA) equal to DATA)
(

*i*) TEMP = HOLD → Next
(

*ii*) HOLD → Next = TEMP → Next
(

*iii*) Set free the node TEMP, which is deleted
(

*iv*) Exit
(

*b*) HOLD = HOLD → Next
5. if ((HOLD → next → DATA) == DATA)

(

*a*) TEMP = HOLD → Next
(

*b*) Set free the node TEMP, which is deleted
(

*c*) HOLD → Next = NULL
(

*d*) Exit
6. Disply “DATA not found”

7. Exit

_{}

^{}

_{}^{}_{}^{}_{}

^{}

## 0 Comments