Insertion in list, Data Structure & Algorithms

In the array implementation of lists, elements are stored into continuous locations. In order to add an element into the list at the end, we can insert it without any problem. But, assume if we desire to add the element at the starting or middle of the list, then we ought to rewrite all the elements after the position where the element ought to be added. We ought to shift (n)th   element to (n+1)th position, where 'n' refer to number of elements in the list. The (n-1)thelement to (n)th position  and it will continue till the ( r ) thelement to ( r + 1 )th position, where 'r' refer to the position of insertion. For doing this, thecount will be incremented.

From the above instance, if we desire to add element '35' after element '33'. We ought to shift 77 to the 8th position, 66 to the 7th position, so on, 44 to the 5th position.

Before Insertion

Count    1     2            3               4               5                    6            7

11

22

33

44

55

66

77

 

 

Step 1

Count  1           2       3            4             5          6          7          8

11

22

33

44

55

66

77

77

Step 2

Count    1      2            3           4            5           6            7          8

11

22

33

44

55

66

66

77

Step 3

Count     1      2      3              4               5          6            7          8

11

22

33

44

55

55

66

77

 

Step 4

Count   1      2            3           4            5            6            7          8

11

22

33

44

44

55

66

77

Step 5

Count     1       2        3           4            5             6            7          8

11

22

33

35

44

55

66

77

Posted Date: 4/11/2013 2:47:49 AM | Location : United States







Related Discussions:- Insertion in list, Assignment Help, Ask Question on Insertion in list, Get Answer, Expert's Help, Insertion in list Discussions

Write discussion on Insertion in list
Your posts are moderated
Related Questions
12345 SOLVE BY USING FOLDING METHOD

Which sorting algorithm is easily adaptable to singly linked lists? Simple Insertion sor t is easily adabtable to singly linked list.

Acyclic Graphs In a directed graph a path is said to form a cycle is there exists a path (A,B,C,.....P) such that A = P. A graph is called acyclic graph if there is no cycle in

Breadth-first search starts at a given vertex h, which is at level 0. In the first stage, we go to all the vertices that are at the distance of one edge away. When we go there, we

Example: (Single rotation into AVL tree, while a new node is inserted into the AVL tree (LL Rotation)) Figure: LL Rotation The rectangles marked A, B & C are trees

write an algorithm to sort given numbers in ascending order using bubble sort


Graphs are data structures which consist of a set of vertices & a set of edges which connect the vertices. A graph where the edges are directed is called directed graph. Or else, i

What are circular queues?  Circular queue: Static queues have a very large drawback that once the queue is FULL, even though we erase few elements from the "front" and relieve

an electrical student designed a circuit in which the impedence in one part of a series circuit is 2+j8 ohms and the impedent is another part of the circuit is 4-j60 ohm mm program