# Find largest and smallest elements in linked list

Here given code implementation process.

``````// C Program
// Find largest and smallest elements in linked list
#include <stdio.h>
//For malloc function
#include <stdlib.h>

struct Node
{
int data;
struct Node *next;
};
//Create a node of linked list
struct Node *create_node(int data)
{
//Create dynamic node
struct Node *node = (struct Node *) malloc(sizeof(struct Node));
if (node == NULL)
{
printf("Memory overflow\n");
}
else
{
//Set initial node value
node->data = data;
node->next = NULL;
}
return node;
}
void insert(struct Node **head, int data)
{
struct Node *node = create_node(data);
{
}
else
{
//Find last node
while (temp->next != NULL)
{
temp = temp->next;
}
temp->next = node;
}
}
{
{
return;
}
while (temp != NULL)
{
printf("  %d", temp->data);
//visit to next node
temp = temp->next;
}
}
//Find the largest and smallest element in linked list
{
{
return;
}
//Define some auxiliary variables
struct Node *big = NULL;
struct Node *small = NULL;
while (temp != NULL)
{
if (big == NULL)
{
//Get first node
big = temp;
}
else if (big->data < temp->data)
{
if (small == NULL)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big->data != temp->data)
{
if (small == NULL || small->data > temp->data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp->next;
}
if (big != NULL)
{
printf("\n Largest  :  %d\n", big->data);
}
if (small != NULL)
{
printf(" Smallest : %d \n", small->data);
}
else
{
//When smallest node are not exist in linked list
printf(" Smallest  : None\n");
}
}
int main()
{
struct Node *list1 = NULL;
struct Node *list2 = NULL;
struct Node *list3 = NULL;
struct Node *list4 = NULL;
insert( &list1, 6);
insert( &list1, 4);
insert( &list1, 5);
insert( &list1, 10);
insert( &list1, 3);
insert( &list1, 7);
insert( &list1, 9);
insert( &list1, 2);
insert( &list1, 8);
largest_smallest(list1);
insert( &list2, 1);
insert( &list2, -3);
insert( &list2, 4);
insert( &list2, 2);
insert( &list2, 3);
insert( &list2, 1);
largest_smallest(list2);
insert( &list3, 2);
insert( &list3, 1);
insert( &list3, 8);
insert( &list3, 4);
insert( &list3, 8);
insert( &list3, 1);
insert( &list3, 3);
insert( &list3, 2);
largest_smallest(list3);
insert( &list4, 2);
insert( &list4, 2);
insert( &list4, 2);
largest_smallest(list4);
return 0;
}``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest  :  10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest  :  4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest  :  8
Smallest : 1

Linked List :   2  2  2
Largest  :  2
Smallest  : None``````
``````// Java Program
// Find largest and smallest elements in linked list

class Node
{
public int data;
public Node next;
public Node(int data)
{
//Set node value
this.data = data;
this.next = null;
}
}
{
public Node tail;
//Class constructor
{
this.tail = null;
}
//insert node at last of linke list
public void insert(int data)
{
//Create a node
Node node = new Node(data);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
public void display()
{
{
return;
}
while (temp != null)
{
//display node value
System.out.print("  " + temp.data);
//visit to next node
temp = temp.next;
}
}
//Find the largest and smallest element in linked list
public void largest_smallest()
{
{
return;
}
this.display();
//Define some auxiliary variables
Node big = null;
Node small = null;
while (temp != null)
{
if (big == null)
{
//Get first node
big = temp;
}
else if (big.data < temp.data)
{
if (small == null)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big.data != temp.data)
{
if (small == null || small.data > temp.data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp.next;
}
if (big != null)
{
System.out.print("\n Largest : " + big.data + "\n");
}
if (small != null)
{
System.out.print(" Smallest : " + small.data + " \n");
}
else
{
//When smallest node are not exist in linked list
System.out.print(" Smallest : None\n");
}
}
public static void main(String[] args)
{
list1.insert(6);
list1.insert(4);
list1.insert(5);
list1.insert(10);
list1.insert(3);
list1.insert(7);
list1.insert(9);
list1.insert(2);
list1.insert(8);
list1.largest_smallest();
list2.insert(1);
list2.insert(-3);
list2.insert(4);
list2.insert(2);
list2.insert(3);
list2.insert(1);
list2.largest_smallest();
list3.insert(2);
list3.insert(1);
list3.insert(8);
list3.insert(4);
list3.insert(8);
list3.insert(1);
list3.insert(3);
list3.insert(2);
list3.largest_smallest();
list4.insert(2);
list4.insert(2);
list4.insert(2);
list4.largest_smallest();
}
}``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None``````
``````//Include header file
#include <iostream>
using namespace std;

// C++ Program
// Find largest and smallest elements in linked list

class Node
{
public: int data;
Node * next;
Node(int data)
{
//Set node value
this->data = data;
this->next = NULL;
}
};
{
Node * tail;
//Class constructor
{
this->tail = NULL;
}
//insert node at last of linke list
void insert(int data)
{
//Create a node
Node * node = new Node(data);
{
this->tail = node;
}
else
{
this->tail->next = node;
this->tail = node;
}
}
void display()
{
{
return;
}
cout << "\n Linked List : ";
while (temp != NULL)
{
//display node value
cout << "  " << temp->data;
//visit to next node
temp = temp->next;
}
}
//Find the largest and smallest element in linked list
void largest_smallest()
{
{
return;
}
this->display();
//Define some auxiliary variables
Node * big = NULL;
Node * small = NULL;
while (temp != NULL)
{
if (big == NULL)
{
//Get first node
big = temp;
}
else if (big->data < temp->data)
{
if (small == NULL)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big->data != temp->data)
{
if (small == NULL || small->data > temp->data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp->next;
}
if (big != NULL)
{
cout << "\n Largest : " << big->data << "\n";
}
if (small != NULL)
{
cout << " Smallest : " << small->data << " \n";
}
else
{
//When smallest node are not exist in linked list
cout << " Smallest : None\n";
}
}
};
int main()
{
list1.insert(6);
list1.insert(4);
list1.insert(5);
list1.insert(10);
list1.insert(3);
list1.insert(7);
list1.insert(9);
list1.insert(2);
list1.insert(8);
list1.largest_smallest();
list2.insert(1);
list2.insert(-3);
list2.insert(4);
list2.insert(2);
list2.insert(3);
list2.insert(1);
list2.largest_smallest();
list3.insert(2);
list3.insert(1);
list3.insert(8);
list3.insert(4);
list3.insert(8);
list3.insert(1);
list3.insert(3);
list3.insert(2);
list3.largest_smallest();
list4.insert(2);
list4.insert(2);
list4.insert(2);
list4.largest_smallest();
return 0;
}``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None``````
``````//Include namespace system
using System;
// C# Program
// Find largest and smallest elements in linked list

public class Node
{
public int data;
public Node next;
public Node(int data)
{
//Set node value
this.data = data;
this.next = null;
}
}
{
public Node tail;
//Class constructor
{
this.tail = null;
}
//insert node at last of linke list
public void insert(int data)
{
//Create a node
Node node = new Node(data);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
public void display()
{
{
return;
}
while (temp != null)
{
//display node value
Console.Write("  " + temp.data);
//visit to next node
temp = temp.next;
}
}
//Find the largest and smallest element in linked list
public void largest_smallest()
{
{
return;
}
this.display();
//Define some auxiliary variables
Node big = null;
Node small = null;
while (temp != null)
{
if (big == null)
{
//Get first node
big = temp;
}
else if (big.data < temp.data)
{
if (small == null)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big.data != temp.data)
{
if (small == null || small.data > temp.data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp.next;
}
if (big != null)
{
Console.Write("\n Largest : " + big.data + "\n");
}
if (small != null)
{
Console.Write(" Smallest : " + small.data + " \n");
}
else
{
//When smallest node are not exist in linked list
Console.Write(" Smallest : None\n");
}
}
public static void Main(String[] args)
{
list1.insert(6);
list1.insert(4);
list1.insert(5);
list1.insert(10);
list1.insert(3);
list1.insert(7);
list1.insert(9);
list1.insert(2);
list1.insert(8);
list1.largest_smallest();
list2.insert(1);
list2.insert(-3);
list2.insert(4);
list2.insert(2);
list2.insert(3);
list2.insert(1);
list2.largest_smallest();
list3.insert(2);
list3.insert(1);
list3.insert(8);
list3.insert(4);
list3.insert(8);
list3.insert(1);
list3.insert(3);
list3.insert(2);
list3.largest_smallest();
list4.insert(2);
list4.insert(2);
list4.insert(2);
list4.largest_smallest();
}
}``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None``````
``````<?php
// Php Program
// Find largest and smallest elements in linked list

class Node
{
public \$data;
public \$next;

function __construct(\$data)
{
//Set node value
\$this->data = \$data;
\$this->next = null;
}
}
{
public \$tail;
//Class constructor
function __construct()
{
\$this->tail = null;
}
//insert node at last of linke list
public	function insert(\$data)
{
//Create a node
\$node = new Node(\$data);
{
\$this->tail = \$node;
}
else
{
\$this->tail->next = \$node;
\$this->tail = \$node;
}
}
public	function display()
{
{
return;
}
echo "\n Linked List : ";
while (\$temp != null)
{
//display node value
echo "  ". \$temp->data;
//visit to next node
\$temp = \$temp->next;
}
}
//Find the largest and smallest element in linked list
public	function largest_smallest()
{
{
return;
}
\$this->display();
//Define some auxiliary variables
\$big = null;
\$small = null;
while (\$temp != null)
{
if (\$big == null)
{
//Get first node
\$big = \$temp;
}
else if (\$big->data < \$temp->data)
{
if (\$small == null)
{
\$small = \$big;
}
//Get current largest node
\$big = \$temp;
}
else if (\$big->data != \$temp->data)
{
if (\$small == null || \$small->data > \$temp->data)
{
//get new smallest
\$small = \$temp;
}
}
//visit to next node
\$temp = \$temp->next;
}
if (\$big != null)
{
echo "\n Largest : ". \$big->data ."\n";
}
if (\$small != null)
{
echo " Smallest : ". \$small->data ." \n";
}
else
{
//When smallest node are not exist in linked list
echo " Smallest : None\n";
}
}
}

function main()
{
\$list1->insert(6);
\$list1->insert(4);
\$list1->insert(5);
\$list1->insert(10);
\$list1->insert(3);
\$list1->insert(7);
\$list1->insert(9);
\$list1->insert(2);
\$list1->insert(8);
\$list1->largest_smallest();
\$list2->insert(1);
\$list2->insert(-3);
\$list2->insert(4);
\$list2->insert(2);
\$list2->insert(3);
\$list2->insert(1);
\$list2->largest_smallest();
\$list3->insert(2);
\$list3->insert(1);
\$list3->insert(8);
\$list3->insert(4);
\$list3->insert(8);
\$list3->insert(1);
\$list3->insert(3);
\$list3->insert(2);
\$list3->largest_smallest();
\$list4->insert(2);
\$list4->insert(2);
\$list4->insert(2);
\$list4->largest_smallest();
}
main();``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None``````
``````// Node Js Program
// Find largest and smallest elements in linked list

class Node
{
constructor(data)
{
//Set node value
this.data = data;
this.next = null;
}
}
{
//Class constructor
constructor()
{
this.tail = null;
}
//insert node at last of linke list
insert(data)
{
//Create a node
var node = new Node(data);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
display()
{
{
return;
}
while (temp != null)
{
//display node value
process.stdout.write("  " + temp.data);
//visit to next node
temp = temp.next;
}
}
//Find the largest and smallest element in linked list
largest_smallest()
{
{
return;
}
this.display();
//Define some auxiliary variables
var big = null;
var small = null;
while (temp != null)
{
if (big == null)
{
//Get first node
big = temp;
}
else if (big.data < temp.data)
{
if (small == null)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big.data != temp.data)
{
if (small == null || small.data > temp.data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp.next;
}
if (big != null)
{
process.stdout.write("\n Largest : " + big.data + "\n");
}
if (small != null)
{
process.stdout.write(" Smallest : " + small.data + " \n");
}
else
{
//When smallest node are not exist in linked list
process.stdout.write(" Smallest : None\n");
}
}
}

function main()
{
list1.insert(6);
list1.insert(4);
list1.insert(5);
list1.insert(10);
list1.insert(3);
list1.insert(7);
list1.insert(9);
list1.insert(2);
list1.insert(8);
list1.largest_smallest();
list2.insert(1);
list2.insert(-3);
list2.insert(4);
list2.insert(2);
list2.insert(3);
list2.insert(1);
list2.largest_smallest();
list3.insert(2);
list3.insert(1);
list3.insert(8);
list3.insert(4);
list3.insert(8);
list3.insert(1);
list3.insert(3);
list3.insert(2);
list3.largest_smallest();
list4.insert(2);
list4.insert(2);
list4.insert(2);
list4.largest_smallest();
}
main();``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None``````
``````#  Python 3 Program
#  Find largest and smallest elements in linked list

class Node :

def __init__(self, data) :
# Set node value
self.data = data
self.next = None

# Class constructor
def __init__(self) :
self.tail = None

# insert node at last of linke list
def insert(self, data) :
# Create a node
node = Node(data)
self.tail = node
else :
self.tail.next = node
self.tail = node

def display(self) :
print("\nEmpty linked list\n", end = "")
return

print("\n Linked List : ", end = "")
while (temp != None) :
# display node value
print("  ", temp.data, end = "")
# visit to next node
temp = temp.next

# Find the largest and smallest element in linked list
def largest_smallest(self) :
print("\nEmpty linked list\n", end = "")
return

self.display()
# Define some auxiliary variables
big = None
small = None
while (temp != None) :
if (big == None) :
# Get first node
big = temp

elif(big.data < temp.data) :
if (small == None) :
small = big

# Get current largest node
big = temp

elif(big.data != temp.data) :
if (small == None or small.data > temp.data) :
# get new smallest
small = temp

# visit to next node
temp = temp.next

if (big != None) :
print("\n Largest : ", big.data ,"\n", end = "")

if (small != None) :
print(" Smallest : ", small.data ," \n", end = "")
else :
# When smallest node are not exist in linked list
print(" Smallest : None\n", end = "")

def main() :
list1.insert(6)
list1.insert(4)
list1.insert(5)
list1.insert(10)
list1.insert(3)
list1.insert(7)
list1.insert(9)
list1.insert(2)
list1.insert(8)
list1.largest_smallest()
list2.insert(1)
list2.insert(-3)
list2.insert(4)
list2.insert(2)
list2.insert(3)
list2.insert(1)
list2.largest_smallest()
list3.insert(2)
list3.insert(1)
list3.insert(8)
list3.insert(4)
list3.insert(8)
list3.insert(1)
list3.insert(3)
list3.insert(2)
list3.largest_smallest()
list4.insert(2)
list4.insert(2)
list4.insert(2)
list4.largest_smallest()

if __name__ == "__main__": main()``````

#### Output

`````` Linked List :    6   4   5   10   3   7   9   2   8
Largest :  10
Smallest :  2

Linked List :    1   -3   4   2   3   1
Largest :  4
Smallest :  -3

Linked List :    2   1   8   4   8   1   3   2
Largest :  8
Smallest :  1

Linked List :    2   2   2
Largest :  2
Smallest : None``````
``````#  Ruby Program
#  Find largest and smallest elements in linked list

class Node

# Define the accessor and reader of class Node
attr_accessor :data, :next

def initialize(data)

# Set node value
self.data = data
self.next = nil
end
end

# Class constructor
def initialize()

self.tail = nil
end
# insert node at last of linke list
def insert(data)

# Create a node
node = Node.new(data)

self.tail = node
else

self.tail.next = node
self.tail = node
end
end
def display()

return
end
while (temp != nil)

# display node value
print("  ", temp.data)
# visit to next node
temp = temp.next
end
end
# Find the largest and smallest element in linked list
def largest_smallest()

return
end
self.display()
# Define some auxiliary variables
big = nil
small = nil
while (temp != nil)

if (big == nil)

# Get first node
big = temp
elsif(big.data < temp.data)

if (small == nil)

small = big
end
# Get current largest node
big = temp
elsif(big.data != temp.data)

if (small == nil || small.data > temp.data)

# get new smallest
small = temp
end
end
# visit to next node
temp = temp.next
end
if (big != nil)

print("\n Largest : ", big.data ,"\n")
end
if (small != nil)

print(" Smallest : ", small.data ," \n")
else

# When smallest node are not exist in linked list
print(" Smallest : None\n")
end
end
end
def main()

list1.insert(6)
list1.insert(4)
list1.insert(5)
list1.insert(10)
list1.insert(3)
list1.insert(7)
list1.insert(9)
list1.insert(2)
list1.insert(8)
list1.largest_smallest()
list2.insert(1)
list2.insert(-3)
list2.insert(4)
list2.insert(2)
list2.insert(3)
list2.insert(1)
list2.largest_smallest()
list3.insert(2)
list3.insert(1)
list3.insert(8)
list3.insert(4)
list3.insert(8)
list3.insert(1)
list3.insert(3)
list3.insert(2)
list3.largest_smallest()
list4.insert(2)
list4.insert(2)
list4.insert(2)
list4.largest_smallest()
end
main()``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None
``````
``````// Scala Program
// Find largest and smallest elements in linked list

class Node(var data: Int,
var next: Node)
{
def this(data: Int)
{
this(data, null);
}
}
var tail: Node)
{
//Class constructor
def this()
{
this(null, null);
}
//insert node at last of linke list
def insert(data: Int): Unit = {
//Create a node
var node: Node = new Node(data);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
def display(): Unit = {
{
return;
}
while (temp != null)
{
//display node value
print("  " + temp.data);
//visit to next node
temp = temp.next;
}
}
//Find the largest and smallest element in linked list
def largest_smallest(): Unit = {
{
return;
}
this.display();
//Define some auxiliary variables
var big: Node = null;
var small: Node = null;
while (temp != null)
{
if (big == null)
{
//Get first node
big = temp;
}
else if (big.data < temp.data)
{
if (small == null)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big.data != temp.data)
{
if (small == null || small.data > temp.data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp.next;
}
if (big != null)
{
print("\n Largest : " + big.data + "\n");
}
if (small != null)
{
print(" Smallest : " + small.data + " \n");
}
else
{
//When smallest node are not exist in linked list
print(" Smallest : None\n");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
list1.insert(6);
list1.insert(4);
list1.insert(5);
list1.insert(10);
list1.insert(3);
list1.insert(7);
list1.insert(9);
list1.insert(2);
list1.insert(8);
list1.largest_smallest();
list2.insert(1);
list2.insert(-3);
list2.insert(4);
list2.insert(2);
list2.insert(3);
list2.insert(1);
list2.largest_smallest();
list3.insert(2);
list3.insert(1);
list3.insert(8);
list3.insert(4);
list3.insert(8);
list3.insert(1);
list3.insert(3);
list3.insert(2);
list3.largest_smallest();
list4.insert(2);
list4.insert(2);
list4.insert(2);
list4.largest_smallest();
}
}``````

#### Output

`````` Linked List :   6  4  5  10  3  7  9  2  8
Largest : 10
Smallest : 2

Linked List :   1  -3  4  2  3  1
Largest : 4
Smallest : -3

Linked List :   2  1  8  4  8  1  3  2
Largest : 8
Smallest : 1

Linked List :   2  2  2
Largest : 2
Smallest : None``````
``````// Swift Program
// Find largest and smallest elements in linked list

class Node
{
var data: Int;
var next: Node? ;
init(_ data: Int)
{
//Set node value
self.data = data;
self.next = nil;
}
}
{
var tail: Node? ;
//Class constructor
init()
{
self.tail = nil;
}
//insert node at last of linke list
func insert(_ data: Int)
{
//Create a node
let node: Node? = Node(data);
{
self.tail = node;
}
else
{
self.tail!.next = node;
self.tail = node;
}
}
func display()
{
{
return;
}
print("\n Linked List : ", terminator: "");
while (temp != nil)
{
//display node value
print("  ", temp!.data, terminator: "");
//visit to next node
temp = temp!.next;
}
}
//Find the largest and smallest element in linked list
func largest_smallest()
{
{
return;
}
self.display();
//Define some auxiliary variables
var big: Node? = nil;
var small: Node? = nil;
while (temp != nil)
{
if (big == nil)
{
//Get first node
big = temp;
}
else if (big!.data < temp!.data)
{
if (small == nil)
{
small = big;
}
//Get current largest node
big = temp;
}
else if (big!.data != temp!.data)
{
if (small == nil || small!.data > temp!.data)
{
//get new smallest
small = temp;
}
}
//visit to next node
temp = temp!.next;
}
if (big != nil)
{
print("\n Largest : ", big!.data ,"\n", terminator: "");
}
if (small != nil)
{
print(" Smallest : ", small!.data ," \n", terminator: "");
}
else
{
//When smallest node are not exist in linked list
print(" Smallest : None\n", terminator: "");
}
}
}
func main()
{

list1.insert(6);
list1.insert(4);
list1.insert(5);
list1.insert(10);
list1.insert(3);
list1.insert(7);
list1.insert(9);
list1.insert(2);
list1.insert(8);
list1.largest_smallest();
list2.insert(1);
list2.insert(-3);
list2.insert(4);
list2.insert(2);
list2.insert(3);
list2.insert(1);
list2.largest_smallest();
list3.insert(2);
list3.insert(1);
list3.insert(8);
list3.insert(4);
list3.insert(8);
list3.insert(1);
list3.insert(3);
list3.insert(2);
list3.largest_smallest();
list4.insert(2);
list4.insert(2);
list4.insert(2);
list4.largest_smallest();
}
main();``````

#### Output

`````` Linked List :    6   4   5   10   3   7   9   2   8
Largest :  10
Smallest :  2

Linked List :    1   -3   4   2   3   1
Largest :  4
Smallest :  -3

Linked List :    2   1   8   4   8   1   3   2
Largest :  8
Smallest :  1

Linked List :    2   2   2
Largest :  2
Smallest : None``````

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.