Program insertion of a node into any circular linked list, Data Structure & Algorithms

Assignment Help:

Program Insertion of a node into any Circular Linked List

Figure depicts a Circular linked list from which an element was deleted.

ALGORITHM (Deletion of an element from a Circular Linked List)

Step 1  Begin

Step 2  if the list is empty, element cannot be eliminated.

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

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

Step 5  End.

2108_Program Insertion of a node into any Circular Linked List.png

Figure: A Circular Linked List through which an element was deleted

(Dotted line indicates the linked that existed prior to deletion)

Program demonstrated the code for the deletion of an element from the Circular linked list.

#include

#include

#define NULL 0

structlinked_list

{

int data;

structlinked_list *next;

};

typedefstructlinked_listclist;

clist *head, *s;

/* prototype of find and delete_function*/

clist * delete_clist(clist *);

clist * find(clist *, int);

/*description of delete_clist      */

clist *delete_clist(clist *start)

{

int key; clist * f, * temp;

printf("\n enter the element to be deleted \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 not fund");

else

{

}

}

temp = f->next->next;

free(f->next);

f->next=temp;

 

return(start);

}

/*description of find function */

clist * find(clist *start, int key)

{

if(start->next->data == key)

return(start);

if(start->next->next == NULL)

return(NULL);

else

find(start->next, key);

}

void main()

{

voidcreate_clist(clist *);

int count(clist *);

void traverse(clist *);

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

s=head;

create_clist(head);

printf(" \n traversing the created clist and the starting address is %u \n", head);

traverse(head);

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

head=delete_clist(head);

printf(" \n traversing the clist after delete_clistand starting address is following %u \n",head);

traverse(head);

}

voidcreate_clist(clist *start)

{

printf("inputthe element -1111 for coming out of loop\n");

scanf("%d", &start->data);

if(start->data == -1111)

start->next=s;

else

{

start->next=(clist*)malloc(sizeof(clist));

create_clist(start->next);

}

}

void traverse(clist *start)

{

if(start->next!=s)

{

printf("data is %d \t next element address is %u\n", start->data,  start- traverse(start->next);

}

}

if(start->next == s)

printf("data is %d \t next element address is %u\n",start->data,   start->next);

int count(clist *start)

{

if(start->next == s)

return 0;

else

}

return(1+count(start->next));

Program: Deletion of an element from the circular linked list


Related Discussions:- Program insertion of a node into any circular linked list

Acyclic graphs, Acyclic Graphs In a directed graph a path is said to fo...

Acyclic Graphs In a directed graph a path is said to form a cycle is there exists a path (A,B,C,.....P) such that A = P. A graph is called acyclic graph if there is no cycle in

Illustrate the operations of the symbol abstract data type, The operations ...

The operations of the Symbol ADT The operations of the Symbol ADT are the following. a==b-returns true if and only if symbols a and bare identical. a symbol bin Unico

Illumination of wire frame, Illumination of wire frame The colour or sh...

Illumination of wire frame The colour or shade that a surface appears to the human eye depends primarily on three  factors : Colour and strength of incoming illumination

How can the third dimension be displayed on the screen, How can the third d...

How can the third dimension be displayed on the screen The main problem in visualization is the display of three-dimensional objects and scenes on two-dimensional screens. How

Representation of a polynomial with a singly linked list, List areutilized ...

List areutilized to maintainPOLYNOMIALS in the memory. For example, we have a functionf(x)= 7x 5 + 9x 4   - 6x³ + 3x². Figure depicts the representation of a Polynomial by means o

Depth-first search (dfs) , In this respect depth-first search (DFS) is the...

In this respect depth-first search (DFS) is the exact reverse process: whenever it sends a new node, it immediately continues to extend from it. It sends back to previously explore

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

Define chaining process of hashing, Chaining In this method, instead of...

Chaining In this method, instead of hashing function value as location we use it as an index into an array of pointers. Every pointer access a chain that holds the element havi

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

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