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

Assignment Help:

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;

}


Related Discussions:- Algorithm to insert a node in between any two nodes

Implementation of stack, In this unit, we have learned how the stacks are i...

In this unit, we have learned how the stacks are implemented using arrays and using liked list. Also, the advantages and disadvantages of using these two schemes were discussed. Fo

Insertion sort, Data array A has data series from 1,000,000 to 1 with step ...

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.

Splaying procedure, For splaying, three trees are maintained, the central, ...

For splaying, three trees are maintained, the central, left & right sub trees. At first, the central subtree is the complete tree and left and right subtrees are empty. The target

Proof, prove that n/100=omega(n)

prove that n/100=omega(n)

Program segment for deletion of any element from the queue, Program segment...

Program segment for deletion of any element from the queue delete() { int delvalue = 0; if (front == NULL) printf("Queue Empty"); { delvalue = front->value;

What is solid modeling, What is Solid modeling Solid modeling is the mo...

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

Demonstrate that dijkstra''s algorithm, Demonstrate that Dijkstra's algorit...

Demonstrate that Dijkstra's algorithm does not necessarily work if some of the costs are negative by finding a digraph with negative costs (but no negative cost dicircuits) for whi

Analysis of algorithms, A common person's faith is that a computer can do a...

A common person's faith is that a computer can do anything. It is far from truth. In realism computer can carry out only definite predefined instructions. The formal illustration o

Techniques of representing polynomials using arrays, Q. Explain any three m...

Q. Explain any three methods or techniques of representing polynomials using arrays. Write which method is most efficient or effective for representing the following polynomials.

Union & intersection of two linklist, how to write an algorithm for unions ...

how to write an algorithm for unions & intersection of two linklists?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd