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
explain the determination of interest rate in the classical system.

The assignment aims at consolidating your knowledge on data mining techniques and developing practical skills through solving a problem of transcription factor binding sites recogn

Suppose we have a set of N agents and a set of N tasks.Each agent can only perform exactly one task and there is a cost associated with each assignment. We would like to find out a

The maximum degree of any vertex in a simple graph with n vertices is (n-1) is the maximum degree of the vertex in a simple graph.

write a algorithsm in c to perform push and pop operations stastic implementation using array ?

Initially Nodes are inserted in an AVL tree in the same manner as an ordinary binary search tree. Though, the insertion algorithm for any AVL tree travels back along with the pa

This unit discussed about data structure called Arrays. The easiest form of array is a one-dimensional array which may be described as a finite ordered set of homogeneous elements

Example of pre order traversal: Reading of a book, since we do not read next chapter unless we complete all sections of previous chapter & all its sections. Figure  : Rea

You need to implement a function which will write out a given user-specified memory location to disk in base 10. That means that you have to convert the large number data structure

Time Complexity:- The time complexity of an algorithm is the amount of time it requires to run to completion. Some of the reasons for studying time complexity are:- We may be in