# Program to Find the Largest Element in a Doubly Linked List

• Write a C program to find maximum element of a doubly linked list.
• Function to print largest element of a doubly linked list.

Given a doubly linked list, we have to find maximum value node of a doubly linked list. For Example:

```Doubly Linked List
2<-->5<-->9<-->1<-->10<-->1
Maximum Element : 10
```
In this program, we will use iteration to traverse doubly linked list and search for maximum element.
Algorithm to find largest node in doubly linked list
• Initialize a variable "max" with data of head node.(max = head->data;)
• Using a loop, traverse doubly linked list until "head" is not equal to NULL.
• For every node, if it's value is larger than max then set max = head->data; else continue.
• At the end of traversal, max will contain the maximum value of given doubly linked list.

In this program, we will use a user defined function "getMaxNode" which takes head pointer of linked list and returns the value of largest node.

```int getMaxNode(struct node *head){
/* Input Validation */
printf("Error : Invalid Input !!!!\n");
return INT_MIN;
}
}
}
return max;
}
```

## C program to print largest nodes of a doubly linked list

```#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

/* A structure of Doubly linked list node */
struct node {
int data;
struct node *prev, *next;

void initialize(){
}

/*
Given a Inserts a node in front of a doubly linked list.
*/
void insert(int num) {
/* Create a new Linked List node */
struct node* newNode = (struct node*) malloc(sizeof(struct node));
newNode->data  = num;
/* Insert newNode before head node */
newNode->prev = NULL;
}

printf("Inserted Element : %d\n", num);
}

/* Input Validation */
printf("Error : Invalid Input !!!!\n");
return INT_MIN;
}
}
}
return max;
}
/*
*/
while (nodePtr != NULL) {
printf("%d", nodePtr->data);
nodePtr = nodePtr->next;
if(nodePtr != NULL)
printf("-><-");
}
}

int main() {
initialize();
/* Insert elements in Doubly linked list */
insert(4);
insert(9);
insert(12);
insert(1);
/* print Doubly Linked list */
/* Printing maximum value node*/
```Inserted Element : 4