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

Last in first out method, This method is the reverse of FIFO and assumes th...

This method is the reverse of FIFO and assumes that each issue of stock is made from latest items received in the enterprises .Thus if the last lot to be received is not sufficient

Algorithms, characteristics of a good algorithm

characteristics of a good algorithm

Merging, merging 4 sorted files containing 50 10 25 and 15 records will tak...

merging 4 sorted files containing 50 10 25 and 15 records will take time

Splaying steps - splay trees, Readjusting for tree modification calls for r...

Readjusting for tree modification calls for rotations in the binary search tree. Single rotations are possible in the left or right direction for moving a node to the root position

Program for linear search, Program for Linear Search. Program: Linear S...

Program for Linear Search. Program: Linear Search /*Program for Linear Search*/ /*Header Files*/ #include #include /*Global Variables*/ int search; int

Division-remainder hashing, According to this, key value is divided by any ...

According to this, key value is divided by any fitting number, generally a prime number, and the division of remainder is utilized as the address for the record. The choice of s

Simulation of queues, Simulation is the process of making an abstract model...

Simulation is the process of making an abstract model of a real world situation in order to be aware of the effect of modifications and alterations and the effect of introducing nu

Darw a flowchart to inputs top speeds of 5000 cars, Write an algorithm in t...

Write an algorithm in the form of a flowchart that: inputs top speeds (in km/hr.) of 5000 cars Outputs fastest speed and the slowest speed Outputs average (mean) s

Define the term ''complexity of an algorithm, Define the term 'complexity o...

Define the term 'complexity of an algorithm; Complexity of an algorithm is the calculate of analysis of algorithm. Analyzing an algorithm means predicting the resources that th

Explain graph traversal, Graph Traversal In many problems we wish to in...

Graph Traversal In many problems we wish to investigate all the vertices in a graph in some systematic order. In graph we often do not have any single vertex singled out as spe

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