Implement Singly, Doubly and Circularly Connected Linked Lists Illustrating
Implement Singly, Doubly and Circularly Connected Linked Lists Illustrating
h>
#include <stdlib.h>
current->next = newNode;
return head;
}
// Function to delete a node with the given data from the singly linked list
struct Node* deleteNode(struct Node* head, int data) {
if (head == NULL) {
return NULL;
}
if (head->data == data) {
struct Node* temp = head;
head = head->next;
free(temp);
return head;
}
if (current->next == NULL) {
// Node with the given data not found
return head;
}
current->next = newNode;
newNode->prev = current;
return head;
}
// Function to delete a node with the given data from the doubly linked list
struct DoublyNode* deleteNodeDoubly(struct DoublyNode* head, int data) {
if (head == NULL) {
return NULL;
}
if (head->data == data) {
struct DoublyNode* temp = head;
head = head->next;
if (head != NULL) {
head->prev = NULL;
}
free(temp);
return head;
}
if (current == NULL) {
// Node with the given data not found
return head;
}
if (current->prev != NULL) {
current->prev->next = current->next;
}
if (current->next != NULL) {
current->next->prev = current->prev;
}
free(current);
return head;
}
current->next = newNode;
newNode->next = head;
return head;
}
// Function to delete a node with the given data from the circular linked list
struct CircularNode* deleteNodeCircular(struct CircularNode* head, int data) {
if (head == NULL) {
return NULL;
}
if (prev != NULL) {
prev->next = current->next;
}
if (current == head) {
head = head->next;
}
free(current);
return head;
}
int main() {
// Singly linked list
struct Node* singlyHead = NULL;
return 0;
}