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
B- Tree  A B-tree of order m is an m-way true in which  1)  All leaves are on the similar level 2)  All internal nodes except the root have at most m-1(non-empty) childre

explain the prims''s algorithm with suitable example?

Q. Explain the result of inserting the keys given. F, S, Q, K, C, L, H, T, V, W, M, R, N, P, A, B, X, Y, D, Z, E  in an order to an empty B-tree of degree-3.

Q. Write an algorithm INSERT which takes a pointer to a sorted list and a pointer to a node and inserts the node into its correct position or place in the list.  Ans: /* s

Q. By making use of stacks, write an algorithm to determine whether the infix expression has balanced parenthesis or not.

for i=1 to n if a[i}>7 for j=2 to n a[j]=a{j}+j for n=2 to n a[k]=a[j]+i else if a[1]>4 && a[1] for 2 to a[1] a[j]= a{j]+5 else for 2to n a[j]=a[j]+i ..

While BFS is applied, the vertices of the graph are divided into two categories. The vertices, that are visited as part of the search & those vertices that are not visited as part

Channel access In first generation systems, every cell supports a number of channels. At any given time a channel is allocated to only one user. Second generation systems also

#question.show that the following inequality is correct or incorrect. n!=O(n^n)

Graphs are data structures which consist of a set of vertices & a set of edges which connect the vertices. A graph where the edges are directed is called directed graph. Or else, i