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

Algorithms for push and pop operation, Q. Suggest a method of implementing ...

Q. Suggest a method of implementing two stacks in one array such that as long as space is there in an array, you should be capable to add an element in either stack. Using proposed

Data structures, 1.  You are required to hand in both a hard copy and an el...

1.  You are required to hand in both a hard copy and an electronic copy of the written report on the project described in A, including all the diagrams you have drawn.  2.  You

Program on radix sort., Write a program that uses the radix sort to sort 10...

Write a program that uses the radix sort to sort 1000 random digits. Print the data before and after the sort. Each sort bucket should be a linked list. At the end of the sort, the

Explain in brief the asymptotic notations, Question 1 Write the different ...

Question 1 Write the different characteristics of an algorithm Question 2 Explain in brief the asymptotic notations Question 3 Write an algorithm of insertion sort and e

Algorithm to sort a given list by quick sort method, Q. Write down an algor...

Q. Write down an algorithm to sort a given list by making use of Quick sort method. Describe the behaviour of Quick sort when input given to us is already sorted.

Enumerate about the concept of container, Enumerate about the concept of co...

Enumerate about the concept of container A Container can have a size() operation. We can also ask (somewhat redundantly) whether a Container is empty. And even though a Contain

Graph, explain the prims''s algorithm with suitable example?

explain the prims''s algorithm with suitable example?

How can the third dimension be displayed on the screen, How can the third d...

How can the third dimension be displayed on the screen The main problem in visualization is the display of three-dimensional objects and scenes on two-dimensional screens. How

Define doubly linked list, A list item stores pointers and an element ...

A list item stores pointers and an element to predecessor and successor. We call a pointer to a list item a handle . This looks simple enough, but pointers are so powerful tha

Techniques of representing polynomials using arrays, Q. Explain any three m...

Q. Explain any three methods or techniques of representing polynomials using arrays. Write which method is most efficient or effective for representing the following polynomials.

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