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

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.

Test whether a binary tree is a binary search tree, Q. Write down an algori...

Q. Write down an algorithm to test whether a Binary Tree is a Binary Search Tree.              A n s . The algorithm to check whether a Binary tree is as Binary Search

B-tree of degree 3, Q. Explain the result of inserting the keys given. ...

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.

Order of linear search, a. In worst case the order of linear search is O (n...

a. In worst case the order of linear search is O (n/2) b. Linear search is more competent than Binary search. c. For Binary search, the array must be sorted in ascending orde

Stack making use of the linked list, Q. Implement a stack making use of the...

Q. Implement a stack making use of the linked list. Show the PUSH and POP operations both. A n s . Stack implemantation using linked list # include # include

Data structures, Aa) Come up with an ERD from the following scenario, clear...

Aa) Come up with an ERD from the following scenario, clearly stating all entities, attributes, relationships before final sketch of the ERD: [50 m

How to write binary search algorithm?, Q. Write down the binary search algo...

Q. Write down the binary search algorithm and trace to search element 91 in following given list: 13          30          62           73         81         88             91

Infix expression into the postfix expression, Q. Convert the given infix ex...

Q. Convert the given infix expression into the postfix expression (also Show the steps) A ∗ (B + D)/ E - F(G + H / k ) Ans. Steps showing Infix to Post fix

Stacks, reverse the order of elements on a stack S using two additional sta...

reverse the order of elements on a stack S using two additional stacks using one additional stack

Find longest repeat prefix of string - linear time algorithm, 1. A string s...

1. A string s is said to be periodic with a period α, if s is α k for some k > 2. (Note that α k is the string formed by concatenating k times.) A DNA sequence s is called a tand

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