Insert function, Data Structure & Algorithms

Assignment Help:

INSERT FUNCTION

/*prototypes of insert & find functions */

list * insert_list(list *);

list * find(list *, int);

/*definition of  anyinsert function */

list * insert_list(list *start)

{

list *n, *f;

int key, element;

printf("enter value of new element");

scanf("%d", &element);

printf("enter value of key element");

scanf("%d",&key);

if(start->data ==key)

{

n=(list *)mallo(sizeof(list));

n->data=element; n->next = start; start=n;

}

else

{

f = find(start, key);

if(f == NULL)

printf("\n key is not found \n");

else

{

n=(list*)malloc(sizeof(list));

n->data=element; n->next=f->next; f->next=n;

}

}

return(start);

}

/*definition of a find function */

list * find(list *start, int key)

{

if(start->next->data == key)

return(start);

if(start->next->next == NULL)

return(NULL);

else

find(start->next, key);

}

void main()

{

list  *head;

void create(list *);

int count(list *);

void traverse(list *);

head=(list *)malloc(sizeof(list));

create(head);

printf(" \ntraversing the list \n");

traverse(head);

printf("\n number of elements in the list   %d \n", count(head));

head=insert_list(head);

printf(" \nafter the insertion of new elementstraverse list \n");

traverse(head);

}

Program: Insertion of an element in a linked list at a particular position


Related Discussions:- Insert function

Signals, How does cpu''s part tming and controls generate and controls sign...

How does cpu''s part tming and controls generate and controls signls in computer?

Deletion of a node from a binary search tree, The algorithm to delete any n...

The algorithm to delete any node having key from a binary search tree is not simple where as several cases has to be considered. If the node to be deleted contains no sons,

Write a program to create a hashed file, Write a program to create a hashed...

Write a program to create a hashed file that stores the records currently in the file " data_2013 ". Records should use the same fixed-length schema given previously, and should ag

Determine about the post conditions assertion, Determine about the Post con...

Determine about the Post conditions assertion A  post condition is an assertion which should be true at completion of an operation. For instance, a post condition of the squ

Execute algorithm to convert infix into post fix expression, Q. Execute you...

Q. Execute your algorithm to convert the infix expression to the post fix expression with the given infix expression as input Q = [(A + B)/(C + D) ↑ (E / F)]+ (G + H)/ I

What is the best case complexity of quick sort, What is the best case compl...

What is the best case complexity of quick sort In the best case complexity, the pivot is in the middle.

Sparse matrix, what are the disadvantages of sparse matrix?

what are the disadvantages of sparse matrix?

Mcs-021, #questWrite an algorithm for multiplication of two sparse matrices...

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

Data type, Q. Define the terms data type and abstract data type. Comment up...

Q. Define the terms data type and abstract data type. Comment upon the significance of both these.   Ans: We determine the total amount of memory to reserve by determining

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