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

Assignment Help:

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 ;

}


Related Discussions:- An algorithm to insert a node in beginning of linked list

What do you understand by tree traversal, What do you understand by tree tr...

What do you understand by tree traversal? The algorithm walks by the tree data structure and performs some computation at everynode in the tree. This process of walking by the

Data structure- tree, Tree is dynamic data structures. Trees can expand & c...

Tree is dynamic data structures. Trees can expand & contract as the program executes and are implemented via pointers. A tree deallocates memory whereas an element is deleted.

Define complete binary tree, Define Complete Binary Tree Complete Binar...

Define Complete Binary Tree Complete Binary Tree:- A whole binary tree of depth d is that strictly binary tree all of whose leaves are at level D.

How many nodes in a tree have no ancestor, How many nodes in a tree have no...

How many nodes in a tree have no ancestors 1 node in atree have no ancestors.

Methods of collision resolution, Methods of Collision Resolution 1)  Co...

Methods of Collision Resolution 1)  Collision Resolution by separate chaining  2)  Collision Resolution by open addressing

Implementation of stack, Implementation of Stack :- Stacks can be execu...

Implementation of Stack :- Stacks can be executed in the 2 ways: a)  Arrays b)  Linked List

Pseudo code, I need help writing a pseudocode for my assignment can anyone ...

I need help writing a pseudocode for my assignment can anyone help?

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd