Professional Documents
Culture Documents
Doubly Linked List1
Doubly Linked List1
Q. Make a doubly linked list so that elements in linked list are always in
ascending order from left to right and print the contents of linked list in ascending
order and descending order.
#include <stdio.h>
#include <stdlib.h>
int main() {
node_type* front = NULL;
node_type* rear = NULL;
int num_elements;
1
Vivek Kumar MCA-B (91)
return 0;
}
if (*front == NULL) {
*front = temp;
*rear = temp;
return;
}
node_type* p = *front;
node_type* prev = NULL;
2
Vivek Kumar MCA-B (91)
if (prev == NULL) {
temp->next = *front;
(*front)->prev = temp;
*front = temp;
} else if (p == NULL) {
prev->next = temp;
temp->prev = prev;
*rear = temp;
} else {
prev->next = temp;
temp->prev = prev;
temp->next = p;
p->prev = temp;
}
}
3
Vivek Kumar MCA-B (91)
4
Vivek Kumar MCA-B (91)
Output->