Deletion of an element from the linked list, Data Structure & Algorithms

Assignment Help:

ALGORITHM (Deletion of an element from the linked list)

Step 1  Begin

Step 2  if the list is empty, then element cannot be deleted

Step 3  else, if the element to be deleted is the first node, then make the start (head) point to the second element.

Step 4  else, Remove the element from list by calling a find function & returning the found address of the element.

Step 5 End

DELETE_LIST FUNCTION

/* prototype of delete_function */

list *delete_list(list *);

list *find(list *, int);

/*definition of delete_list */

list *delete_list(list *start)

{

int key; list * f, * temp;

printf("\n Insert the element to be purged \n");

scanf("%d", &key);

if(start->data == key)

{

temp=start->next;

free(start); start=temp;

}

else

{

f = find(start,key);

if(f==NULL)

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

else

{

temp = f->next->next;

free(f->next);

f->next=temp;

}

}

return(start);

}

void main()

{

list  *head;

void create(list *);

int count(list *);

void traverse(list *);

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

create(head);

printf(" \n traverse created list \n");

traverse(head);

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

head=insert(head);

printf(" \n traverse list after adding desiredelement \n");

traverse(head);

head=delete_list(head);

printf(" \n traverse list after delete_list \n");

traverse(head);

}

Program: Deletion of any element from the linked list by searching for element i.e. to be deleted


Related Discussions:- Deletion of an element from the linked list

Determine the complexity, 1)    The set of the algorithms whose order is O ...

1)    The set of the algorithms whose order is O (1) would run in the identical time.  True/False 2)    Determine the complexity of the following program into big O notation:

Types of tree ?, Binary: Each node has one, zero, or two children. This ...

Binary: Each node has one, zero, or two children. This assertion creates many tree operations efficient and simple. Binary Search : A binary tree where each and every left

Bst created in pre- order, Q. Make a BST for the given sequence of numbe...

Q. Make a BST for the given sequence of numbers. 45,32,90,34,68,72,15,24,30,66,11,50,10 Traverse the BST formed in  Pre- order, Inorder and Postorder.

Draw a b-tree., Q. Draw a B-tree of order 3 for the sequence of keys writte...

Q. Draw a B-tree of order 3 for the sequence of keys written below: 2, 4, 9, 8, 7, 6, 3, 1, 5, 10

Optimization Methods, Optimal solution to the problem given below. Obtain t...

Optimal solution to the problem given below. Obtain the initial solution by VAM Ware houses Stores Availibility I II III IV A 5 1 3 3 34 B 3 3 5 4 15 C 6 4 4 3 12 D 4 –1 4 2 19 Re

Avl tree rotations, AVL trees and the nodes it contains must meet strict ba...

AVL trees and the nodes it contains must meet strict balance requirements to maintain O(log n) search time. These balance restrictions are kept maintained via various rotation func

Explain the different types of traversal on binary tree, Question 1 What i...

Question 1 What is a data structure? Discuss briefly on types of data structures Question 2 Explain the insertion and deletion operation of linked list in detail Qu

Explain multidimensional array, Multidimensional array: Multidimensional a...

Multidimensional array: Multidimensional arrays can be defined as "arrays of arrays". For example, a bidimensional array can be imagined as a bidimensional table made of elements,

Array and two-dimensional array, Q. Describe the term array.  How do we rep...

Q. Describe the term array.  How do we represent two-dimensional arrays in memory?  Explain how we calculate the address of an element in a two dimensional array.

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