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
In this respect depth-first search (DFS) is the exact reverse process: whenever it sends a new node, it immediately continues to extend from it. It sends back to previously explore

Draw trace table and determine the output from the below flowchart using following data (NOTE: input of the word "end" stops program and outputs results of survey):  Vehicle = c

find the grammar of regular expression of (a/?)(a/b)?

explain implementation of circular queue insert,delete operations

what is the difference between data type and abstract data type

HEAP  A heap is described to be a binary tree with a key in every node, such that  1-All the leaves of the tree are on 2 adjacent levels. 2- All leaves on the lowest leve

Write an algorithm to calculate a postfix expression.  Execute your algorithm using the given postfix expression as your input : a b + c d +*f ↑ . T o evaluate a postfix expr

Question 1 Write the different characteristics of an algorithm Question 2 Explain in brief the asymptotic notations Question 3 Write an algorithm of insertion sort and e

What are expression trees?  The leaves of an expression tree are operands, like as constants or variable names, and the other nodes have operators. This certain tree happens to

calculate gpa using an algorithm