answersLogoWhite

0


Best Answer

This depends on whether the list is singly or doubly(or multiply) linked, and on the actual implementation of the list. For example, you can write a CDLL(circular doubly linked list) without maintaining your beginning or ending nodes, using only a current pointer, thus this question doesn't really apply as there would be no "last" node and thus it would be like deleting any node.

A typical implementation of a circular singly-linked list (CSLL) list actually maintains the pointer to the last element (hence it's FIFO nature) and thus there are both last and first nodes.

This deletion is a little tricky. Consider that you have situations where the next pointer will point to the current element. On the other hand, you also have a situation where there are n-values that you have to iterate over to find the next-to-last value. Typically you would delete the first node in these lists, again dictated by the FIFO nature of these lists, but deletion of the last node is also not impossible.

set struct node *last to list->end

if (list->end->next == list->end){

set list->end to null (leaving an empty list)

} else {

while(true){

if(last->next == list->end){

break

}

set last to last->next

}

set link->last to list->end->next (this temporarily sets list's end node to current first node)

free last->next (frees the last node)

set last->next to list->end (set the new last node next pointer to the first node)

set list->end to last (set the list's end node to the new last node)

}

User Avatar

Wiki User

11y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Write algorithm to delete last node in circular linked list?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a algorithm for doubly linked list in c?

sorry


How do you write a Java program to implement weighted queue using circular doubly linked list?

Add weights to the elements of the queue and use an algorithm to sort the queue every time an element is added.


Write a program in C to create a Circular Linked list?

#include<iostream.h>


Write an algorithm for the implementation of a circular doubly linked list?

Create a new node, making sure it is not allocated locally in the function and thus will not be destroyed when the function execution finishesFill in dataUse the "last node" pointer in the list and copy the "next" pointer location (pointing to the first node) into the new nodes "next" pointerSet the "last node" "next" pointer to point to the new nodeChange the list's "last node" pointer to point to the new nodeFor an example of implementation see: How_you_insert_a_newnode_in_singly_circular_link_list


How to write aC program to merge two singly linked list?

write a c program to circular queue


Write an Algorithm to delete a last element from the array?

// Assuming you dynamically allocated this array using "new"... delete array[arraysize - 1]; arraysize--;


Explain Pseudo code for circular linked list?

write pseudocode for link list


Write an algorithm for inserting an element in a circular linked list?

Given a currentNode pointer, perform the following steps: Create a newNode. Assign currentNode->next to newNode->next. Assign currentNode to newNode->prev. Assign newNode to currentNode->next.


3 Write the algorithm of inserting an element at middle of a linked?

theory part to how u can insert element at middle of link list ?


Write an algorithm?

Algorithms are simply a set of steps to take in order to reach an answer. It is often linked with computer programming and can be written in plain english.


What is algorithm to write algorithm to the program to access a pointer variable in structure?

Here is the algorithm of the algorithm to write an algorithm to access a pointer in a variable. Algorithmically.name_of_the_structure dot name_of_the _field,eg:mystruct.pointerfield


How to write an actual algorithm for inserting an element in a linked list?

Insert newNode into a linked list after targetNode Node currentNode = root while currentNode != targetNode currentNode = currentNode.next newNode.next = currentNode.next currentNode.next = newNode