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
How can the third dimension be displayed on the screen The main problem in visualization is the display of three-dimensional objects and scenes on two-dimensional screens. How

If a Dequeue is implemented via arrays, then this will suffer with the similar problems which a linear queue had suffered. Program 8 gives the array implementation of Dequeue.

write aprogram for random -search to implement if a[i]=x;then terminate other wise continue the search by picking new randon inex into a

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

A queue is a, FIFO (First In First Out) list.

Define the External Path Length The External Path Length E of an extended binary tree is explained as the sum of the lengths of the paths - taken over all external nodes- from

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

What is binary search?   Binary search is most useful when list is sorted. In binary search, element present in middle of the list is determined. If key (the number to search)

Deletion Algorithm for dequeue Step 1: [check for underflow]   If front = 0 and rear = 0   Output "underflow" and return Step 2: [delete element at front end]   If front

Surrounding of sub division method A polygon surrounds a viewport if it completely encloses or covers the viewport. This happens if none of its sides cuts any edge of the viewp