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
Let a be a well-formed formula. Let c be the number of binary logical operators in a. (Recall that ?, ?, ?, and ? are the binary logical operators). Let s be the number of proposit


Define the term counting - Pseudocode Counting in 1s is quite simple; use of statement count = count + 1 would enable counting to be done (for example in controlling a repeat

Indexed Sequential Files An index is inserted to the sequential file to provide random access. An overflow area required to be maintained to permit insertion in sequence. I

#questWrite an algorithm for multiplication of two sparse matrices using Linked Lists.ion..

A telephone directory having n = 10 records and Name field as key. Let us assume that the names are stored in array 'm' i.e. m(0) to m(9) and the search has to be made for name "X"

Consider the file " search_2013 ". This is a text file containingsearch key values; each entry is a particular ID (in the schema given above). You are tosimulate searching over a h

Explain in detail the algorithmic implementation of multiple stacks.

Conceptually, the stack abstract data type mimics the information kept into a pile on a desk. Informally, first we consider a material on a desk, where we might keep separate stack

A graph with n vertices will absolutely have a parallel edge or self loop if the total number of edges is greater than n-1