An algorithm to insert a node in beginning of linked list, Data Structure & Algorithms

Q. Write down an algorithm to insert a node in the beginning of the linked list.                        

Ans:

/* structure containing a link part and link part data part */

struct node

{

int data ;

struct node * link ;

} ;

/* Following adds a new node at the beginning of the linked list */

void addatbeg ( struct node **q, int num )

{

struct node *temp ;

/* add new node */

temp = malloc ( sizeof ( struct node ) ) ;

temp -> data = num ;

temp -> link = *q ;

*q = temp ;

}

Posted Date: 7/10/2012 5:23:19 AM | Location : United States







Related Discussions:- An algorithm to insert a node in beginning of linked list, Assignment Help, Ask Question on An algorithm to insert a node in beginning of linked list, Get Answer, Expert's Help, An algorithm to insert a node in beginning of linked list Discussions

Write discussion on An algorithm to insert a node in beginning of linked list
Your posts are moderated
Related Questions
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.

RGB Model The RGB model is based on the assumption that any desired shade of colour can be obtained by mixing the correct amounts of red, green, and blue light. The exact hues

Linear search employee an exhaustive method of verified each element in the array against a key value. Whereas a match is found, the search halts. Will sorting the array before uti

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.

what is far and near procedures in system programming?

A representation of an array structure is a mapping of the (abstract) array with elements of type T onto the store which is an array with elements of type BYTE. The array could be

what do we use asymptotic notation in study of algorithm?Describe various asymptotic notation and give their significance.

Which sorting algorithm is easily adaptable to singly linked lists? Simple Insertion sor t is easily adabtable to singly linked list.

Any Binary search tree has to contain following properties to be called as a red- black tree. 1. Each node of a tree must be either red or black. 2. The root node is always b

What do you understand by term structured programming? Explain the structured programming as well.                                 Ans. S tructured Programming is expla