Javatpoint Logo
Javatpoint Logo

9. Python program to find the maximum and minimum value node from a doubly linked list.

In this program, we will create a doubly linked list then, iterate through the list to find out the minimum and maximum node.

Python program to find the maximum and minimum value node from a doubly linked list

We will maintain two variables min and max. Min will hold the minimum value node, and max will hold the maximum value node. In the above example, 1 will be the minimum value node and 9 will be the maximum value node

ALGORITHM:

  1. Define a Node class which represents a node in the list. It will have three properties: data, previous which will point to the previous node and next which will point to the next node.
  2. Define another class for creating the doubly linked list, and it has two nodes: head and tail. Initially, head and tail will point to null.
  3. minimumNode() will prints out minimum value node:
  • Define variable min and initialize with head's data.
  • Current will point to head.
  • Iterate through the list by comparing each node's data with min.
  • If min > current's data then min will hold current's data.
  • At the end of the list, variable min will hold the minimum value node.
  • Print the min value.

a. maximumNode() will prints out maximum value node:

  • Define variable max and initialize with head's data.
  • Current will point to head.
  • Iterate through the list by comparing each node's data with max.
  • If max < current's data then max will hold current's data.
  • At the end of the list, variable max will hold the maximum value node.
  • Print the max value.

PROGRAM:

Output:

Minimum value node in the list: 1
Maximum value node in the list: 9
Next TopicPython Programs





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA