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

Characterstics of good algorithm, what are the charaterstics to determine w...

what are the charaterstics to determine weather an algorithm is good or not? explain in detail

Link list, algorithm for multiplication of two sparse matrices using link l...

algorithm for multiplication of two sparse matrices using link list

What are the dynamic arrays, What are the Dynamic arrays Dynamic arrays...

What are the Dynamic arrays Dynamic arrays are convenient for programmers since they can never be too small-whenever more space is needed in a dynamic array, it can simply be e

Functions and modelling the data flows, Read the scenario (Pickerings Prope...

Read the scenario (Pickerings Properties). (a) List the functions of the system, as perceived by an external user. (b) List the external entities. Note that because we are mo

Algorithm to find maximum and minimum numbers, Give an algorithm to find bo...

Give an algorithm to find both the maximum and minimum of 380 distinct numbers that uses at most 568 comparisons.

Insertion sort, Data array A has data series from 1,000,000 to 1 with step ...

Data array A has data series from 1,000,000 to 1 with step size 1, which is in perfect decreasing order. Data array B has data series from 1 to 1,000,000, which is in random order.

Single pointer pointing to the tail of the queue, Can a Queue be shown by c...

Can a Queue be shown by circular linked list with only single pointer pointing to the tail of the queue? Yes a Queue can be shown by a circular linked list with only single p

Binary search trees, A Binary Search Tree is binary tree which is either em...

A Binary Search Tree is binary tree which is either empty or a node having a key value, left child & right child. By analyzing the above definition, we notice that BST comes int

Logic circuits, the voltage wave forms are applied at the inputs of an EX-O...

the voltage wave forms are applied at the inputs of an EX-OR gate. determine the output wave form

Define the internal path length, Define the Internal Path Length The In...

Define the Internal Path Length The Internal Path Length I of an extended binary tree is explained as the sum of the lengths of the paths taken over all internal nodes- from th

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