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

Multiple queue, algorithm for multiple queue with example program

algorithm for multiple queue with example program

Data structures, I am looking for assignment help on the topic Data Structu...

I am looking for assignment help on the topic Data Structures. It would be great if anyone help me.

Array implementation of a multiqueue, Program gives the program segment by ...

Program gives the program segment by using arrays for the insertion of an element to a queue into the multiqueue. Program: Program segment for the insertion of any element to t

The game tree, An interesting application or implementation of trees is the...

An interesting application or implementation of trees is the playing of games such as tie-tac-toe, chess, nim, kalam, chess, go etc. We can depict the sequence of possible moves

Algorithm that counts number of nodes in a linked list, Q. Write an algorit...

Q. Write an algorithm that counts number of nodes in a linked list.                                       A n s . Algo rithm to Count No. of Nodes in Linked List C

Context sensitive f1 help on a field, In what ways we can get the context s...

In what ways we can get the context sensitive F1 help on a field?' Data element documentation. Data element additional text in screen painter. Using the process on help r

Reverse order of elements on a slack, Q. Describe the representations of gr...

Q. Describe the representations of graph. Represent the graph which is given to us using any two methods Ans: The different ways by which we can represent graphs are:

Row major representation, Row Major Representation In memory the primar...

Row Major Representation In memory the primary method of representing two-dimensional array is the row major representation. Under this representation, the primary row of the a

All pairs shortest paths, N = number of rows of the graph D[i[j] = C[i][...

N = number of rows of the graph D[i[j] = C[i][j] For k from 1 to n Do for i = 1 to n Do for j = 1 to n D[i[j]= minimum( d ij (k-1) ,d ik (k-1) +d kj (k-1)

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