Write procedure to the insert a node into the linked list, Data Structure & Algorithms

Q. Write a procedure to the insert a node into the linked list at a particular position and draw the same by taking an example?                                                                                                       

Ans:

* Insert (after legal position p).*/

/* Header implementation assumed. */

void insert( element_type x, LIST L, position p )

{

position tmp_cell;

tmp_cell = (position) malloc( sizeof (struct node));

if( tmp_cell == NULL )

fatal_error("Out of space!!!");

else

{

tmp_cell->element = x; tmp_cell->next = p->next; p->next = tmp_cell;

}

}

1421_linked list.png

Posted Date: 7/11/2012 1:41:27 AM | Location : United States







Related Discussions:- Write procedure to the insert a node into the linked list, Assignment Help, Ask Question on Write procedure to the insert a node into the linked list, Get Answer, Expert's Help, Write procedure to the insert a node into the linked list Discussions

Write discussion on Write procedure to the insert a node into the linked list
Your posts are moderated
Related Questions
The simplest implementation of the Dijkstra's algorithm stores vertices of set Q into an ordinary linked list or array, and operation Extract-Min(Q) is just a linear search through

Merging 4 sorted files having 50, 10, 25 and 15 records will take time

Post order traversal: The children of node are visited before the node itself; the root is visited last. Each node is visited after its descendents are visited. Algorithm fo

The two famous methods for traversing are:- a) Depth first traversal b) Breadth first

null(nil) = true                     // nil refer for empty tree null(fork(e, T, T'))= false   //  e : element , T and T are two sub tree leaf(fork(e, nil, nil)) = true leaf(

write a COBOL program to find the biggest of two numbers

There are four data type groups:  Integer kepts whole numbers and signed numbers Floating-point Stores real numbers (fractional values). Perfect for storing bank deposit

Example of Back Face Detection Method To illustrate the method, we shall start with the tetrahedron (pyramid) PQRS of     Figure with vertices P (1, 1, 2), Q (3, 2, 3), R (1,

The Euclidean algorithm is an algorithm to decide the greatest common divisor of two positive integers. The greatest common divisor of N and M, in short GCD(M,N), is the largest in

algorithm for multiple queue with example program