Algorithm For Insertion Of An Element In List Explain with Example In Data Structure.
Insertion of an Element in List
Algorithm:
locate the position where the element in to be inserted (position may be user-specified in case of an unsorted list or may be decided by search for a sorted list)
reorganize the list and create an ‘empty’ slot
insert the element
Example: (sorted list)
data: 345 358 490 501 513 555 561 701 724 797
location: 0 1 2 3 4 5 6 7 8 9
Insert 505 onto the above list:
Locate the appropriate position by performing a binary search. 505 should be stored in location 4.
Create an ‘empty’ slot
data: 345 358 490 501 513 555 561 701 724 797
location: 0 1 2 3 4 5 6 7 8 9 10
Insert 505
data: 345 358 490 501 505 513 555 561 701 724 797
location: 0 1 2 3 4 5 6 7 8 9 10
Labels: Data Structure