Doubly Linked List
Doubly Linked List
Doubly Linked List
#include <stdio.h>
#include <stdlib.h>
temp->next = newNode;
newNode->prev = temp;
return head;
}
// Function to traverse the list forward and print the data of each node
void traverseForward(struct Node* head) {
struct Node* temp = head;
printf("Forward: ");
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
// Function to traverse the list backward and print the data of each node
void traverseBackward(struct Node* tail) {
struct Node* temp = tail;
printf("Backward: ");
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->prev;
}
printf("NULL\n");
}
// Function to free the memory allocated for the doubly linked list
void freeList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
struct Node* next = temp->next;
free(temp);
temp = next;
}
}
int main() {
struct Node* head = NULL; // Initialize the list to NULL
struct Node* tail = NULL; // Initialize the tail to NULL
return 0;
}
Program-02 Deletion in Doubly linked list
#include <stdio.h>
#include <stdlib.h>
temp->next = newNode;
newNode->prev = temp;
return head;
}
// Function to traverse the list forward and print the data of each node
void traverseForward(struct Node* head) {
struct Node* temp = head;
printf("Forward: ");
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
// Function to free the memory allocated for the doubly linked list
void freeList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
struct Node* next = temp->next;
free(temp);
temp = next;
}
}
int main() {
struct Node* head = NULL; // Initialize the list to NULL
#include <stdio.h>
#include <stdlib.h>
// Function to traverse the list forward and print the data of each node
void traverseForward(struct Node* head) {
struct Node* temp = head;
printf("Forward: ");
while (temp != NULL) {
printf("%d -> ", temp->data);
temp = temp->next;
}
printf("NULL\n");
}
// Function to free the memory allocated for the doubly linked list
void freeList(struct Node* head) {
struct Node* temp = head;
while (temp != NULL) {
struct Node* next = temp->next;
free(temp);
temp = next;
}
}
int main() {
struct Node* head = NULL; // Initialize the list to NULL