Question

write a function to delete the largest item from a sorted (asc) Circular Linked List (a...

write a function to delete the largest item from a sorted (asc) Circular Linked List (a CLLNode is list where the last element is pointing to head).

Homework Answers

Answer #1

C code is given below for more understanding with output:

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>

typedef struct A
{
int value;
struct A *next;
}NODE;
NODE *head;


int main()
{

//create 4 node circular link list:
head=(NODE*)malloc(sizeof(NODE));
scanf("%d",&head->value);
head->next=NULL;
NODE *ptr=head ,*temp;
int i;
for(i=1;i<=3;i++)
{

temp=(NODE*)malloc(sizeof(NODE));
scanf("%d",&temp->value);
temp->next=NULL;

head->next=temp;
head=temp;
}
head->next=ptr;

//a circular list created and head denote to last node:

//Now Delete largest element:
//circular link list before deletion:
printf("Circular link list before deletion\n");
print(head,ptr);
NODE *head1=head;
while(head1->next!=head)
head1=head1->next;
head1->next=head->next;
free(head);
head=head1;
//circular link list after deletion:
printf("\nCircular link list after deletion:\n");
print(head,ptr);


return 0;

}

int print(NODE *ptr , NODE *head)
{
while(head!=ptr)
{
printf("%d -> ",head->value);
head=head->next;
}
printf("%d",ptr->value);
return 0;
}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
When we delete an existing item from an unsorted linked list and insert a new item...
When we delete an existing item from an unsorted linked list and insert a new item into a sorted linked list, we use temporary pointers to hold addresses of nodes. Please explain how many pointers we need and why. You could use a chart/diagram to show the difference.
Write a function to accept a header of a sorted linked and a name which can...
Write a function to accept a header of a sorted linked and a name which can be used as a key. If the key is found then add the record to the linked list using pointer(s). Do not write complete program. Write just one function. I just need a function that can demonstrate the prompt above.
Write a program in prolog to delete all reference of a particular item from a list....
Write a program in prolog to delete all reference of a particular item from a list. It should have three arguments. The list you wish to use, the item to delete, and the resulting list. Here are some example of it behaviour ?- delete_all([a,b,a,c,a,d],a,Result). Result = [b,c,d] ? - delete_all([a,b,a,c,a,d],b,Result). Result = [a,a,c,a,d]
Delete an item from a circular queue and return the index of the next item. (java)
Delete an item from a circular queue and return the index of the next item. (java)
How do you delete the tail node of a singly linked list if the link has...
How do you delete the tail node of a singly linked list if the link has the head and does not have tail? Write the code. How much time does it take to Do it?
How do you delete the tail node of a singly linked list if the link has...
How do you delete the tail node of a singly linked list if the link has the head and does no have tail? Write the code. How much time does it take to do it? (java)
Write a recursive function elemAt that returns the ith item of the list, where the first...
Write a recursive function elemAt that returns the ith item of the list, where the first item is index 0. You may not use any of the standard Haskell functions that operate on lists. For Example: List is [5,6,7,78,8,7]          Element at index 3 is 78
public class DoublyLinkedList { Node Head; // head of Doubly Linked List //Doubly Linked list Node...
public class DoublyLinkedList { Node Head; // head of Doubly Linked List //Doubly Linked list Node class Node { int value; Node prev; Node next; // Constructor to create a new node Node(int d) { value = d; } } // Inserting a node at the front of the list public void add(int newData) { // allocate node and put in the data Node newNode = new Node(newData); // Make the next of new node as head // and previous...
Assume that struct Node{ int item; Node*link; }; Write function NodePtr list_search(NodePtr head, int target); The...
Assume that struct Node{ int item; Node*link; }; Write function NodePtr list_search(NodePtr head, int target); The function will search through the linked list that is pointed by head and return a NodePtr that points to the Node that contains target as its item. If there is no such a Node, NULL will be returned. c++
Write C language code for a function that takes a doubly linked list as a parameter...
Write C language code for a function that takes a doubly linked list as a parameter and deletes all the nodes in even positions from the first to the last after displaying the content of each node to the console.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT