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

Sparse matrix, How sparse matrix stored in the memory of a computer?

How sparse matrix stored in the memory of a computer?

Tree traversals, There are three kinds of tree traversals, namely, Postorde...

There are three kinds of tree traversals, namely, Postorder , Preorder and Inorder. Preorder traversal: Each of nodes is visited before its children are visited; first the roo

Algorithm to count number of nodes, Write an algorithm to count number of n...

Write an algorithm to count number of nodes in the circular linked list.                            Ans. Counting No of Nodes in Circular List Let list be a circular h

Comp. sci algorithms, 1. develop an algorithm which reads two decimal numbe...

1. develop an algorithm which reads two decimal numbers x and y and determines and prints out wether x>y or y>x. the input values, x and y, are whole number > or equal to 0, which

What do you understand by structured programming, What do you understand by...

What do you understand by structured programming Structured Programming  This term is used for programming design that emphasizes:- (1) Hierarchical design of programmi

Proof, prove that n/100=omega(n)

prove that n/100=omega(n)

Graph & optimal scheduling, You are given an undirected graph G = (V, E) in...

You are given an undirected graph G = (V, E) in which the edge weights are highly restricted. In particular, each edge has a positive integer weight of either {1,2,...,W}, where W

Explain the interfaces in ruby, Explain the Interfaces in Ruby Recall...

Explain the Interfaces in Ruby Recall that in object-oriented programming, an interface is a collection of abstract operations that cannot be instantiated. Even though Ruby i

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