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
Normal 0 false false false EN-IN X-NONE X-NONE MicrosoftInternetExplorer4

ESO207: Programming Assignment 1 Due on 6 Sept, 2015. To be submitted online. Problem In this assignment you are required to implement k-way Merge Sort algorithm. In this version p

Develop a program that accepts the car registration( hint: LEA 43242010)

Linked list representations contain great advantages of flexibility on the contiguous representation of data structures. However, they contain few disadvantages also. Data structur

What are the different ways of representing a graph? The different ways of representing a graph is: Adjacency list representation: This representation of graph having of an

Which sorting methods would be most suitable for sorting a list which is almost sorted  Bubble Sorting method.


Explain principle of Optimality It indicates that an optimal solution to any instance of an optimization problem is composed of  optimal solutions to its subinstances.

Q. Define the sparse metrics and also explain the representation of a 4X4 matrix using linked list.         Ans: A matrix in which number of zero entries is quite h

Let G=(V,E) be a graph for which all nodes have degree 5 and where G is 5-edge is connected. a) Show that the vector x which is indexed by the edges E and for which xe = 1/5 for