Algorithm to insert a node in between any two nodes, Data Structure & Algorithms

Q. Write down an algorithm to insert a node in between any two nodes in a linked list       

Ans.

Insertion of a the node after the given element of the listis as follows

Node *  InsertAfterElement (node * start, int item, int after)

{

node * ptr, * loc;

ptr =(node *) malloc (sizeof (node));

ptr->info = item;

loc=start;

while (loc != NULL && loc->info != after)

loc= loc->next;

if (start==NULL) { ptr->next= NULL;

start = ptr;}

else if (loc l = NULL){ ptr->next = loc->next; loc->next= ptr;}

return start;

}

Posted Date: 7/12/2012 8:29:20 AM | Location : United States







Related Discussions:- Algorithm to insert a node in between any two nodes, Assignment Help, Ask Question on Algorithm to insert a node in between any two nodes, Get Answer, Expert's Help, Algorithm to insert a node in between any two nodes Discussions

Write discussion on Algorithm to insert a node in between any two nodes
Your posts are moderated
Related Questions
Ans: I nsertion into the B-tree: 1.  First search is made for the place where the new record must be positioned. As soon as the keys are inserted, they are sorted into th

Explain the bubble sort algorithm. Answer This algorithm is used for sorting a list. It makes use of a temporary variable for swapping. It compares two numbers at an insta

How to create multiple queue on single array?

Ways to implement abstract data types A large part of the study of data structures and algorithms is learning about alternative ways to implement an ADT and evaluating alternat

Define File organization''s and it''s types

what algorithms can i use for the above title in my project desing and implmentation of road transport booking system

The below formula is used to calculate n: n = (x * x)/ (1 - x). Value x = 0 is used to stop the algorithm. Calculation is repeated using values of x until value x = 0 is input. The

What is Solid modeling Solid modeling is the most powerful of the 3-D modeling technique. It provides the user with complete information about the model. Defining an object wit

A striking application of DFS is determine a strongly connected component of a graph. Definition: For graph G = (V, E) , where V refer to the set of vertices and E refer to the

Evaluate the frequency counts for all statements in the following given program segment. for (i=1; i ≤ n; i ++) for (j = 1; j ≤ i; j++) for (k =1; k ≤ j; k++) y ++;