# Delete nodes which have a greater value on right side

Given a linked list, Which include integer node values. Our goal is to remove all nodes which value is less than on right side node. This problem is based on linked list traversal and node deletion with specified condition. Lets see few examples to understand this problem.

``````Example
----------
List    1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
-------------------------------------------
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
1 < 2 (Yes) Delete node 1

2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
2 < 5 (Yes) Delete node 2

5 → 4 → 3 → 6 → 7 → 8 → NULL
5 < 4 (No)

5 → 4 → 3 → 6 → 7 → 8 → NULL
4 < 3 (No)

5 → 4 → 3 → 6 → 7 → 8 → NULL
3 < 6 (Yes) Delete node 3

5 → 4 → 6 → 7 → 8 → NULL
6 < 7 (Yes)

5 → 4 → 7 → 8 → NULL
7 < 8 (Yes) Delete node 7

5 → 4 → 8 → NULL
-------------------------------------------
Output :    5 → 4 → 8 → NULL
``````

Here given code implementation process.

``````/*
C program for
Delete nodes which have a greater value on right side
*/
#include <stdio.h>
#include <stdlib.h>

{
int data;
};
struct SingleLL
{
};
// Returns the new linked list
{
// Create memory of head and tail Nodes
struct SingleLL *sll =
(struct SingleLL *) malloc(sizeof(struct SingleLL));
if (sll == NULL)
{
printf("Memory overflow\n");
}
else
{
sll->tail = NULL;
}
return sll;
}
void appendNode(struct SingleLL *sll, struct LinkNode *node)
{
{
}
else
{
// Append the node at last position
sll->tail->next = node;
}
sll->tail = node;
}
void addNode(struct SingleLL *sll, int data)
{
// Create dynamic node
if (node == NULL)
{
return;
}
else
{
// Set initial node value
node->data = data;
node->next = NULL;
}
appendNode(sll, node);
}
void display(struct SingleLL *sll)
{
{
return;
}
while (temp != NULL)
{
printf(" %d →", temp->data);
// Visit to next node
temp = temp->next;
}
printf(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
void deleteNode(struct SingleLL *sll)
{
{
return;
}
// Define some auxiliary variables
// Execute loop until the last node
while (current != NULL && current->next != NULL)
{
if (current->next->data > current->data)
{
// When next node value is higher to current node
// Get current node
auxiliary = current;
// visit to next node
current = current->next;
if (back == NULL)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back->next = current;
}
// remove current node
free(auxiliary);
auxiliary = NULL;
}
else
{
back = current;
current = current->next;
}
}
}
// Handle request to delete node
void deleteByNextHigher(struct SingleLL *sll)
{
{
return;
}
// Before Delete
printf("\n Given Linked List  : \n");
display(sll);
deleteNode(sll);
// After delete
printf(" After Delete Linked List  : \n");
display(sll);
}
int main(int argc, char
const *argv[])
{
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
deleteByNextHigher(sll1);
deleteByNextHigher(sll2);
deleteByNextHigher(sll3);
return 0;
}``````

#### Output

`````` Given Linked List  :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````// Include header file
#include <iostream>
using namespace std;
/*
C++ program for
Delete nodes which have a greater value on right side
*/
{
public: int data;
{
this->data = data;
this->next = NULL;
}
};
class SingleLL
{
SingleLL()
{
this->tail = NULL;
}
{
{
}
else
{
// Append the node at last position
this->tail->next = node;
}
this->tail = node;
}
void display()
{
{
return;
}
while (temp != NULL)
{
cout << " " << temp->data << " →";
// Visit to next node
temp = temp->next;
}
cout << " NULL\n";
}
// This are perform the deletion operation
// by using next upcoming higher node
void deleteNode()
{
{
return;
}
// Define some auxiliary variables
// Execute loop until the last node
while (current != NULL && current->next != NULL)
{
if (current->next->data > current->data)
{
// When next node value is higher to current node
// Get current node
auxiliary = current;
// visit to next node
current = current->next;
if (back == NULL)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back->next = current;
}
// remove current node
delete (auxiliary);
auxiliary = NULL;
}
else
{
back = current;
current = current->next;
}
}
}
// Handle request to delete node
void deleteByNextHigher()
{
{
cout << "\n Empty Linked List \n";
return;
}
// Before Delete
cout << "\n Given Linked List : \n";
this->display();
this->deleteNode();
// After delete
cout << " After Delete Linked List : \n";
this->display();
}
};
int main()
{
SingleLL *sll1 = new SingleLL();
SingleLL *sll2 = new SingleLL();
SingleLL *sll3 = new SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1->deleteByNextHigher();
sll2->deleteByNextHigher();
sll3->deleteByNextHigher();
return 0;
}``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````/*
Java program for
Delete nodes which have a greater value on right side
*/
{
public int data;
{
this.data = data;
this.next = null;
}
}
public class SingleLL
{
public SingleLL()
{
this.tail = null;
}
{
{
}
else
{
// Append the node at last position
this.tail.next = node;
}
this.tail = node;
}
public void display()
{
{
return;
}
while (temp != null)
{
System.out.print(" " + temp.data + " →");
// Visit to next node
temp = temp.next;
}
System.out.print(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
public void deleteNode()
{
{
return;
}
// Define some auxiliary variables
// Execute loop until the last node
while (current != null && current.next != null)
{
if (current.next.data > current.data)
{
// When next node value is higher to current node
// visit to next node
current = current.next;
if (back == null)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back.next = current;
}
}
else
{
back = current;
current = current.next;
}
}
}
// Handle request to delete node
public void deleteByNextHigher()
{
{
return;
}
// Before Delete
System.out.print("\n Given Linked List : \n");
this.display();
this.deleteNode();
// After delete
System.out.print(" After Delete Linked List : \n");
this.display();
}
public static void main(String[] args)
{
SingleLL sll1 = new SingleLL();
SingleLL sll2 = new SingleLL();
SingleLL sll3 = new SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher();
sll2.deleteByNextHigher();
sll3.deleteByNextHigher();
}
}``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````// Include namespace system
using System;
/*
Csharp program for
Delete nodes which have a greater value on right side
*/
{
public int data;
{
this.data = data;
this.next = null;
}
}
public class SingleLL
{
public SingleLL()
{
this.tail = null;
}
{
{
}
else
{
// Append the node at last position
this.tail.next = node;
}
this.tail = node;
}
public void display()
{
{
return;
}
while (temp != null)
{
Console.Write(" " + temp.data + " →");
// Visit to next node
temp = temp.next;
}
Console.Write(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
public void deleteNode()
{
{
return;
}
// Define some auxiliary variables
// Execute loop until the last node
while (current != null && current.next != null)
{
if (current.next.data > current.data)
{
// When next node value is higher to current node
// visit to next node
current = current.next;
if (back == null)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back.next = current;
}
}
else
{
back = current;
current = current.next;
}
}
}
// Handle request to delete node
public void deleteByNextHigher()
{
{
return;
}
// Before Delete
Console.Write("\n Given Linked List : \n");
this.display();
this.deleteNode();
// After delete
Console.Write(" After Delete Linked List : \n");
this.display();
}
public static void Main(String[] args)
{
SingleLL sll1 = new SingleLL();
SingleLL sll2 = new SingleLL();
SingleLL sll3 = new SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher();
sll2.deleteByNextHigher();
sll3.deleteByNextHigher();
}
}``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````package main
import "fmt"
/*
Go program for
Delete nodes which have a greater value on right side
*/
data int
}
me.data = data
me.next = nil
return me
}
type SingleLL struct {
}
func getSingleLL() * SingleLL {
var me *SingleLL = &SingleLL {}
me.tail = nil
return me
}
} else {
// Append the node at last position
this.tail.next = node
}
this.tail = node
}
func(this SingleLL) display() {
return
}
for (temp != nil) {
fmt.Print(" ", temp.data, " →")
// Visit to next node
temp = temp.next
}
fmt.Print(" NULL\n")
}
// This are perform the deletion operation
// by using next upcoming higher node
func(this *SingleLL) deleteNode() {
return
}
// Define some auxiliary variables
var back * LinkNode = nil
// Execute loop until the last node
for (current != nil && current.next != nil) {
if current.next.data > current.data {
// When next node value is higher to current node
// visit to next node
current = current.next
if back == nil {
// When need to remove a head node
} else {
// Connect previous node to next node
back.next = current
}
} else {
back = current
current = current.next
}
}
}
// Handle request to delete node
func(this *SingleLL) deleteByNextHigher() {
return
}
// Before Delete
fmt.Print("\n Given Linked List : \n")
this.display()
this.deleteNode()
// After delete
fmt.Print(" After Delete Linked List : \n")
this.display()
}
func main() {
var sll1 * SingleLL = getSingleLL()
var sll2 * SingleLL = getSingleLL()
var sll3 * SingleLL = getSingleLL()
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher()
sll2.deleteByNextHigher()
sll3.deleteByNextHigher()
}``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````<?php
/*
Php program for
Delete nodes which have a greater value on right side
*/
{
public \$data;
public \$next;
public	function __construct(\$data)
{
\$this->data = \$data;
\$this->next = NULL;
}
}
class SingleLL
{
public \$tail;
public	function __construct()
{
\$this->tail = NULL;
}
{
{
}
else
{
// Append the node at last position
\$this->tail->next = \$node;
}
\$this->tail = \$node;
}
public	function display()
{
{
return;
}
while (\$temp != NULL)
{
echo(" ".\$temp->data.
" →");
// Visit to next node
\$temp = \$temp->next;
}
echo(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
public	function deleteNode()
{
{
return;
}
// Define some auxiliary variables
\$back = NULL;
// Execute loop until the last node
while (\$current != NULL && \$current->next != NULL)
{
if (\$current->next->data > \$current->data)
{
// When next node value is higher to current node
// visit to next node
\$current = \$current->next;
if (\$back == NULL)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
\$back->next = \$current;
}
}
else
{
\$back = \$current;
\$current = \$current->next;
}
}
}
// Handle request to delete node
public	function deleteByNextHigher()
{
{
return;
}
// Before Delete
echo("\n Given Linked List : \n");
\$this->display();
\$this->deleteNode();
// After delete
echo(" After Delete Linked List : \n");
\$this->display();
}
}

function main()
{
\$sll1 = new SingleLL();
\$sll2 = new SingleLL();
\$sll3 = new SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
\$sll1->deleteByNextHigher();
\$sll2->deleteByNextHigher();
\$sll3->deleteByNextHigher();
}
main();``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````/*
Node JS program for
Delete nodes which have a greater value on right side
*/
{
constructor(data)
{
this.data = data;
this.next = null;
}
}
class SingleLL
{
constructor()
{
this.tail = null;
}
{
{
}
else
{
// Append the node at last position
this.tail.next = node;
}
this.tail = node;
}
display()
{
{
return;
}
while (temp != null)
{
process.stdout.write(" " + temp.data + " →");
// Visit to next node
temp = temp.next;
}
process.stdout.write(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
deleteNode()
{
{
return;
}
// Define some auxiliary variables
var back = null;
// Execute loop until the last node
while (current != null && current.next != null)
{
if (current.next.data > current.data)
{
// When next node value is higher to current node
// visit to next node
current = current.next;
if (back == null)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back.next = current;
}
}
else
{
back = current;
current = current.next;
}
}
}
// Handle request to delete node
deleteByNextHigher()
{
{
return;
}
// Before Delete
process.stdout.write("\n Given Linked List : \n");
this.display();
this.deleteNode();
// After delete
process.stdout.write(" After Delete Linked List : \n");
this.display();
}
}

function main()
{
var sll1 = new SingleLL();
var sll2 = new SingleLL();
var sll3 = new SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher();
sll2.deleteByNextHigher();
sll3.deleteByNextHigher();
}
main();``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````#    Python 3 program for
#    Delete nodes which have a greater value on right side

def __init__(self, data) :
self.data = data
self.next = None

class SingleLL :
def __init__(self) :
self.tail = None

else :
#  Append the node at last position
self.tail.next = node

self.tail = node

def display(self) :
return

while (temp != None) :
print("", temp.data ,"→", end = "")
#  Visit to next node
temp = temp.next

print(" NULL")

#  This are perform the deletion operation
#  by using next upcoming higher node
def deleteNode(self) :
return

#  Define some auxiliary variables
back = None
#  Execute loop until the last node
while (current != None and current.next != None) :
if (current.next.data > current.data) :
#  When next node value is higher to current node
#  visit to next node
current = current.next
if (back == None) :
#  When need to remove a head node
else :
#  Connect previous node to next node
back.next = current

else :
back = current
current = current.next

#  Handle request to delete node
def deleteByNextHigher(self) :
return

#  Before Delete
print("\n Given Linked List : ")
self.display()
self.deleteNode()
#  After delete
print(" After Delete Linked List : ")
self.display()

def main() :
sll1 = SingleLL()
sll2 = SingleLL()
sll3 = SingleLL()
#   1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
#   6 → 3 → 2 → NULL
#   1 → 2 → 3 → NULL
#  Test
sll1.deleteByNextHigher()
sll2.deleteByNextHigher()
sll3.deleteByNextHigher()

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

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````#    Ruby program for
#    Delete nodes which have a greater value on right side

attr_accessor :data, :next
def initialize(data)
self.data = data
self.next = nil
end

end

class SingleLL
# Define the accessor and reader of class SingleLL
def initialize()
self.tail = nil
end

else

#  Append the node at last position
self.tail.next = node
end

self.tail = node
end

def display()
return
end

while (temp != nil)
print(" ", temp.data ," →")
#  Visit to next node
temp = temp.next
end

print(" NULL\n")
end

#  This are perform the deletion operation
#  by using next upcoming higher node
def deleteNode()
return
end

#  Define some auxiliary variables
back = nil
#  Execute loop until the last node
while (current != nil && current.next != nil)
if (current.next.data > current.data)
#  When next node value is higher to current node
#  visit to next node
current = current.next
if (back == nil)
#  When need to remove a head node
else

#  Connect previous node to next node
back.next = current
end

else

back = current
current = current.next
end

end

end

#  Handle request to delete node
def deleteByNextHigher()
return
end

#  Before Delete
print("\n Given Linked List : \n")
self.display()
self.deleteNode()
#  After delete
print(" After Delete Linked List : \n")
self.display()
end

end

def main()
sll1 = SingleLL.new()
sll2 = SingleLL.new()
sll3 = SingleLL.new()
#   1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
#   6 → 3 → 2 → NULL
#   1 → 2 → 3 → NULL
#  Test
sll1.deleteByNextHigher()
sll2.deleteByNextHigher()
sll3.deleteByNextHigher()
end

main()``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL
``````
``````/*
Scala program for
Delete nodes which have a greater value on right side
*/
{
def this(data: Int)
{
this(data,null);
}
}
{
def this()
{
this(null,null);
}
def addNode(data: Int): Unit = {
{
}
else
{
// Append the node at last position
this.tail.next = node;
}
this.tail = node;
}
def display(): Unit = {
{
return;
}
while (temp != null)
{
print(" " + temp.data + " →");
// Visit to next node
temp = temp.next;
}
print(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
def deleteNode(): Unit = {
{
return;
}
// Define some auxiliary variables
// Execute loop until the last node
while (current != null && current.next != null)
{
if (current.next.data > current.data)
{
// When next node value is higher to current node
// visit to next node
current = current.next;
if (back == null)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back.next = current;
}
}
else
{
back = current;
current = current.next;
}
}
}
// Handle request to delete node
def deleteByNextHigher(): Unit = {
{
return;
}
// Before Delete
print("\n Given Linked List : \n");
this.display();
this.deleteNode();
// After delete
print(" After Delete Linked List : \n");
this.display();
}
}
object Main
{
def main(args: Array[String]): Unit = {
var sll1: SingleLL = new SingleLL();
var sll2: SingleLL = new SingleLL();
var sll3: SingleLL = new SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher();
sll2.deleteByNextHigher();
sll3.deleteByNextHigher();
}
}``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````/*
Swift 4 program for
Delete nodes which have a greater value on right side
*/
{
var data: Int;
init(_ data: Int)
{
self.data = data;
self.next = nil;
}
}
class SingleLL
{
init()
{
self.tail = nil;
}
{
{
}
else
{
// Append the node at last position
self.tail!.next = node;
}
self.tail = node;
}
func display()
{
{
return;
}
while (temp  != nil)
{
print("", temp!.data ,"→", terminator: "");
// Visit to next node
temp = temp!.next;
}
print(" NULL");
}
// This are perform the deletion operation
// by using next upcoming higher node
func deleteNode()
{
{
return;
}
// Define some auxiliary variables
// Execute loop until the last node
while (current  != nil && current!.next  != nil)
{
if (current!.next!.data > current!.data)
{
// When next node value is higher to current node
// visit to next node
current = current!.next;
if (back == nil)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back!.next = current;
}
}
else
{
back = current;
current = current!.next;
}
}
}
// Handle request to delete node
func deleteByNextHigher()
{
{
return;
}
// Before Delete
print("\n Given Linked List : ");
self.display();
self.deleteNode();
// After delete
print(" After Delete Linked List : ");
self.display();
}
}
func main()
{
let sll1: SingleLL = SingleLL();
let sll2: SingleLL = SingleLL();
let sll3: SingleLL = SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher();
sll2.deleteByNextHigher();
sll3.deleteByNextHigher();
}
main();``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````
``````/*
Kotlin program for
Delete nodes which have a greater value on right side
*/
{
var data: Int;
constructor(data: Int)
{
this.data = data;
this.next = null;
}
}
class SingleLL
{
constructor()
{
this.tail = null;
}
{
{
}
else
{
// Append the node at last position
this.tail?.next = node;
}
this.tail = node;
}
fun display(): Unit
{
{
return;
}
while (temp != null)
{
print(" " + temp.data + " →");
// Visit to next node
temp = temp.next;
}
print(" NULL\n");
}
// This are perform the deletion operation
// by using next upcoming higher node
fun deleteNode(): Unit
{
{
return;
}
// Define some auxiliary variables
var back: LinkNode ? = null;
// Execute loop until the last node
while (current != null && current.next != null)
{
if (current.next!!.data > current.data)
{
// When next node value is higher to current node
// visit to next node
current = current.next;
if (back == null)
{
// When need to remove a head node
}
else
{
// Connect previous node to next node
back.next = current;
}
}
else
{
back = current;
current = current.next;
}
}
}
// Handle request to delete node
fun deleteByNextHigher(): Unit
{
{
return;
}
// Before Delete
print("\n Given Linked List : \n");
this.display();
this.deleteNode();
// After delete
print(" After Delete Linked List : \n");
this.display();
}
}
fun main(args: Array < String > ): Unit
{
val sll1: SingleLL = SingleLL();
val sll2: SingleLL = SingleLL();
val sll3: SingleLL = SingleLL();
//  1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
//  6 → 3 → 2 → NULL
//  1 → 2 → 3 → NULL
// Test
sll1.deleteByNextHigher();
sll2.deleteByNextHigher();
sll3.deleteByNextHigher();
}``````

#### Output

`````` Given Linked List :
1 → 2 → 5 → 4 → 3 → 6 → 7 → 8 → NULL
5 → 4 → 8 → NULL

6 → 3 → 2 → NULL
6 → 3 → 2 → NULL

1 → 2 → 3 → NULL
3 → NULL``````

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.