Add the given digit to a number stored in a linked list

Here given code implementation process.

``````// C Program
// Add the given digit to a number stored in a linked list
#include <stdio.h>
#include <stdlib.h> //for malloc function

{
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
{
}
return sll;
}
// Returns a new Node of linked list
{
// Create dynamic node
if (node == NULL)
{
printf("Memory overflow\n");
}
else
{
// Set initial node value
node->data = data;
node->next = NULL;
}
return node;
}
void addNode(struct SingleLL *sll, int data)
{
if (data < 0)
{
printf("\n Number is negative : %d \n", data);
return;
}
else if (data > 9)
{
printf("\n Two digit number is not allowed : %d \n", data);
return;
}
{
}
else
{
// Find last node
while (temp->next != NULL)
{
temp = temp->next;
}
// Append the node at last position
temp->next = node;
}
}
void display(struct SingleLL *sll)
{
{
return;
}
while (temp != NULL)
{
{
printf("→");
}
printf(" %d ", temp->data);
// Visit to next node
temp = temp->next;
}
printf("→ NULL\n");
}
void addDigit(struct SingleLL *sll, int digit)
{
if (digit < 0 || digit > 9)
{
printf("\n Invalid digit : %d\n", digit);
return;
}
{
return;
}
// Find last node and
// Detect last node which is contain value of less than 9,
// If it is exist
while (temp->next != NULL)
{
if (temp->data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp->next;
}
temp->data = temp->data + digit;
if (temp->data > 9)
{
// When need to update linked list
if (auxiliary == NULL)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp->data = temp->data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary->next != NULL)
{
auxiliary->data = (auxiliary->data + 1) % 10;
// Visit to next node
auxiliary = auxiliary->next;
}
}
}
int main()
{
// Create a empty linked list
//  9 → 9 → 9 → 8 → 9 → NULL
display(sll);
int digit = 9;
printf(" Add digit : %d \n", digit);
display(sll);
digit = 6;
printf(" Add digit : %d \n", digit);
display(sll);
digit = 5;
printf(" Add digit : %d \n", digit);
display(sll);
return 0;
}``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````/*
Java Program for
Add the given digit to a number stored in a linked list
*/
{
public int data;
{
this.data = data;
this.next = null;
}
};
public class SingleLL
{
public SingleLL()
{
}
{
if (data < 0)
{
System.out.print("\n Number is negative : " + data + " \n");
return;
}
else if (data > 9)
{
System.out.print("\n Two digit number is not allowed : " + data + " \n");
return;
}
{
}
else
{
//Find last node
while (temp.next != null)
{
temp = temp.next;
}
// Append the node at last position
temp.next = node;
}
}
public void display()
{
{
return;
}
while (temp != null)
{
{
System.out.print(" →");
}
System.out.print(" " + temp.data);
// Visit to next node
temp = temp.next;
}
System.out.print(" → NULL\n");
}
{
if (digit < 0 || digit > 9)
{
System.out.print("\n Invalid digit : " + digit + "\n");
return;
}
{
return;
}
// Find last node and
// Detect last node which is contain value of less than 9,
// If it is exist
while (temp.next != null)
{
if (temp.data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp.next;
}
temp.data = temp.data + digit;
if (temp.data > 9)
{
// When need to update linked list
if (auxiliary == null)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp.data = temp.data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary.next != null)
{
auxiliary.data = (auxiliary.data + 1) % 10;
// Visit to next node
auxiliary = auxiliary.next;
}
}
}
public static void main(String[] args)
{
// Create a empty linked list
SingleLL sll = new SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
int digit = 9;
System.out.print(" Add digit : " + digit + " \n");
sll.display();
digit = 6;
System.out.print(" Add digit : " + digit + " \n");
sll.display();
digit = 5;
System.out.print(" Add digit : " + digit + " \n");
sll.display();
}
}``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````// Include header file
#include <iostream>

using namespace std;
/*
C++ Program for
Add the given digit to a number stored in a linked list
*/
{
public:
int data;
{
this->data = data;
this->next = NULL;
}
};;
class SingleLL
{
public:
SingleLL()
{
}
{
if (data < 0)
{
cout << "\n Number is negative : " << data << " \n";
return;
}
else if (data > 9)
{
cout << "\n Two digit number is not allowed : " << data << " \n";
return;
}
{
}
else
{
//Find last node
while (temp->next != NULL)
{
temp = temp->next;
}
// Append the node at last position
temp->next = node;
}
}
void display()
{
{
cout << "\n Empty linked list\n";
return;
}
while (temp != NULL)
{
{
cout << " →";
}
cout << " " << temp->data;
// Visit to next node
temp = temp->next;
}
cout << " → NULL\n";
}
{
if (digit < 0 || digit > 9)
{
cout << "\n Invalid digit : " << digit << "\n";
return;
}
{
cout << "\n Empty linked list\n";
return;
}
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (temp->next != NULL)
{
if (temp->data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp->next;
}
temp->data = temp->data + digit;
if (temp->data > 9)
{
// When need to update linked list
if (auxiliary == NULL)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp->data = temp->data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary->next != NULL)
{
auxiliary->data = (auxiliary->data + 1) % 10;
// Visit to next node
auxiliary = auxiliary->next;
}
}
}
};
int main()
{
// Create a empty linked list
SingleLL sll = SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
int digit = 9;
cout << " Add digit : " << digit << " \n";
sll.display();
digit = 6;
cout << " Add digit : " << digit << " \n";
sll.display();
digit = 5;
cout << " Add digit : " << digit << " \n";
sll.display();
return 0;
}``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````// Include namespace system
using System;
/*
C# Program for
Add the given digit to a number stored in a linked list
*/
{
public int data;
{
this.data = data;
this.next = null;
}
};
public class SingleLL
{
public SingleLL()
{
}
{
if (data < 0)
{
Console.Write("\n Number is negative : " + data + " \n");
return;
}
else if (data > 9)
{
Console.Write("\n Two digit number is not allowed : " + data + " \n");
return;
}
{
}
else
{
//Find last node
while (temp.next != null)
{
temp = temp.next;
}
// Append the node at last position
temp.next = node;
}
}
public void display()
{
{
return;
}
while (temp != null)
{
{
Console.Write(" →");
}
Console.Write(" " + temp.data);
// Visit to next node
temp = temp.next;
}
Console.Write(" → NULL\n");
}
{
if (digit < 0 || digit > 9)
{
Console.Write("\n Invalid digit : " + digit + "\n");
return;
}
{
return;
}
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (temp.next != null)
{
if (temp.data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp.next;
}
temp.data = temp.data + digit;
if (temp.data > 9)
{
// When need to update linked list
if (auxiliary == null)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp.data = temp.data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary.next != null)
{
auxiliary.data = (auxiliary.data + 1) % 10;
// Visit to next node
auxiliary = auxiliary.next;
}
}
}
public static void Main(String[] args)
{
// Create a empty linked list
SingleLL sll = new SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
int digit = 9;
Console.Write(" Add digit : " + digit + " \n");
sll.display();
digit = 6;
Console.Write(" Add digit : " + digit + " \n");
sll.display();
digit = 5;
Console.Write(" Add digit : " + digit + " \n");
sll.display();
}
}``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````<?php
/*
Php Program for
Add the given digit to a number stored in a linked list
*/
{
public \$data;
public \$next;

function __construct(\$data)
{
\$this->data = \$data;
\$this->next = null;
}
};
class SingleLL
{

function __construct()
{
}
{
if (\$data < 0)
{
echo "\n Number is negative : ". \$data ." \n";
return;
}
else if (\$data > 9)
{
echo "\n Two digit number is not allowed : ". \$data ." \n";
return;
}
{
}
else
{
//Find last node
while (\$temp->next != null)
{
\$temp = \$temp->next;
}
// Append the node at last position
\$temp->next = \$node;
}
}
public	function display()
{
{
return;
}
while (\$temp != null)
{
{
echo " →";
}
echo " ". \$temp->data;
// Visit to next node
\$temp = \$temp->next;
}
echo " → NULL\n";
}
{
if (\$digit < 0 || \$digit > 9)
{
echo "\n Invalid digit : ". \$digit ."\n";
return;
}
{
return;
}
\$auxiliary = null;
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (\$temp->next != null)
{
if (\$temp->data < 9)
{
\$auxiliary = \$temp;
}
// Visit to next node
\$temp = \$temp->next;
}
\$temp->data = \$temp->data + \$digit;
if (\$temp->data > 9)
{
// When need to update linked list
if (\$auxiliary == null)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
\$temp->data = \$temp->data % 10;
// Update the node value from auxiliary to second last node
while (\$auxiliary->next != null)
{
\$auxiliary->data = (\$auxiliary->data + 1) % 10;
// Visit to next node
\$auxiliary = \$auxiliary->next;
}
}
}
}

function main()
{
// Create a empty linked list
\$sll = new SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
\$sll->display();
\$digit = 9;
echo " Add digit : ". \$digit ." \n";
\$sll->display();
\$digit = 6;
echo " Add digit : ". \$digit ." \n";
\$sll->display();
\$digit = 5;
echo " Add digit : ". \$digit ." \n";
\$sll->display();
}
main();``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````/*
Node Js Program for
Add the given digit to a number stored in a linked list
*/
{
constructor(data)
{
this.data = data;
this.next = null;
}
};
class SingleLL
{
constructor()
{
}
{
if (data < 0)
{
process.stdout.write("\n Number is negative : " + data + " \n");
return;
}
else if (data > 9)
{
process.stdout.write("\n Two digit number is not allowed : " + data + " \n");
return;
}
{
}
else
{
//Find last node
while (temp.next != null)
{
temp = temp.next;
}
// Append the node at last position
temp.next = node;
}
}
display()
{
{
return;
}
while (temp != null)
{
{
process.stdout.write(" →");
}
process.stdout.write(" " + temp.data);
// Visit to next node
temp = temp.next;
}
process.stdout.write(" → NULL\n");
}
{
if (digit < 0 || digit > 9)
{
process.stdout.write("\n Invalid digit : " + digit + "\n");
return;
}
{
return;
}
var auxiliary = null;
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (temp.next != null)
{
if (temp.data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp.next;
}
temp.data = temp.data + digit;
if (temp.data > 9)
{
// When need to update linked list
if (auxiliary == null)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp.data = temp.data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary.next != null)
{
auxiliary.data = (auxiliary.data + 1) % 10;
// Visit to next node
auxiliary = auxiliary.next;
}
}
}
}

function main()
{
// Create a empty linked list
var sll = new SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
var digit = 9;
process.stdout.write(" Add digit : " + digit + " \n");
sll.display();
digit = 6;
process.stdout.write(" Add digit : " + digit + " \n");
sll.display();
digit = 5;
process.stdout.write(" Add digit : " + digit + " \n");
sll.display();
}
main();``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````#   Python 3 Program for
#   Add the given digit to a number stored in a linked list

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

class SingleLL :

def __init__(self) :

if (data < 0) :
print("\n Number is negative : ", data ," ")
return

elif(data > 9) :
print("\n Two digit number is not allowed : ", data ," ")
return

else :
# Find last node
while (temp.next != None) :
temp = temp.next

#  Append the node at last position
temp.next = node

def display(self) :
return

while (temp != None) :
print(" →", end = "")

print("", temp.data, end = "")
#  Visit to next node
temp = temp.next

print(" → NULL")

if (digit < 0 or digit > 9) :
print("\n Invalid digit : ", digit )
return

return

auxiliary = None
#  Find last node and
#  Detect last node which is contain value of less than 9,
#  If it is exist
while (temp.next != None) :
if (temp.data < 9) :
auxiliary = temp

#  Visit to next node
temp = temp.next

temp.data = temp.data + digit
if (temp.data > 9) :
#  When need to update linked list
if (auxiliary == None) :
#  When auxiliary is NULL then assign first node to this
#  Create a new node

#  Manage last node
temp.data = temp.data % 10
#  Update the node value from auxiliary to second last node
while (auxiliary.next != None) :
auxiliary.data = (auxiliary.data + 1) % 10
#  Visit to next node
auxiliary = auxiliary.next

def main() :
#  Create a empty linked list
sll = SingleLL()
#   9 → 9 → 9 → 8 → 9 → NULL
sll.display()
digit = 9
print(" Add digit : ", digit ," ")
sll.display()
digit = 6
print(" Add digit : ", digit ," ")
sll.display()
digit = 5
print(" Add digit : ", digit ," ")
sll.display()

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

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````#   Ruby Program for
#   Add the given digit to a number stored in a linked list

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()
end

if (data < 0)
print("\n Number is negative : ", data ," \n")
return
elsif(data > 9)
print("\n Two digit number is not allowed : ", data ," \n")
return
end

else
# Find last node
while (temp.next != nil)
temp = temp.next
end

#  Append the node at last position
temp.next = node
end

end

def display()
return
end

while (temp != nil)
print(" →")
end

print(" ", temp.data)
#  Visit to next node
temp = temp.next
end

print(" → NULL\n")
end

if (digit < 0 || digit > 9)
print("\n Invalid digit : ", digit ,"\n")
return
return
end

auxiliary = nil
#  Find last node and
#  Detect last node which is contain value of less than 9,
#  If it is exist
while (temp.next != nil)
if (temp.data < 9)
auxiliary = temp
end

#  Visit to next node
temp = temp.next
end

temp.data = temp.data + digit
if (temp.data > 9)
#  When need to update linked list
if (auxiliary == nil)
#  When auxiliary is NULL then assign first node to this
#  Create a new node
end

#  Manage last node
temp.data = temp.data % 10
#  Update the node value from auxiliary to second last node
while (auxiliary.next != nil)
auxiliary.data = (auxiliary.data + 1) % 10
#  Visit to next node
auxiliary = auxiliary.next
end

end

end

end

def main()
#  Create a empty linked list
sll = SingleLL.new()
#   9 → 9 → 9 → 8 → 9 → NULL
sll.display()
digit = 9
print(" Add digit : ", digit ," \n")
sll.display()
digit = 6
print(" Add digit : ", digit ," \n")
sll.display()
digit = 5
print(" Add digit : ", digit ," \n")
sll.display()
end

main()``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL
``````
``````/*
Scala Program for
Add the given digit to a number stored in a linked list
*/
{
def this(data: Int)
{
this(data, null);
}
};
{
def this()
{
this(null);
}
def addNode(data: Int): Unit = {
if (data < 0)
{
print("\n Number is negative : " + data + " \n");
return;
}
else if (data > 9)
{
print("\n Two digit number is not allowed : " + data + " \n");
return;
}
{
}
else
{
//Find last node
while (temp.next != null)
{
temp = temp.next;
}
// Append the node at last position
temp.next = node;
}
}
def display(): Unit = {
{
return;
}
while (temp != null)
{
{
print(" →");
}
print(" " + temp.data);
// Visit to next node
temp = temp.next;
}
print(" → NULL\n");
}
def addDigit(digit: Int): Unit = {
if (digit < 0 || digit > 9)
{
print("\n Invalid digit : " + digit + "\n");
return;
}
{
return;
}
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (temp.next != null)
{
if (temp.data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp.next;
}
temp.data = temp.data + digit;
if (temp.data > 9)
{
// When need to update linked list
if (auxiliary == null)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp.data = temp.data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary.next != null)
{
auxiliary.data = (auxiliary.data + 1) % 10;
// Visit to next node
auxiliary = auxiliary.next;
}
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
// Create a empty linked list
var sll: SingleLL = new SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
var digit: Int = 9;
print(" Add digit : " + digit + " \n");
sll.display();
digit = 6;
print(" Add digit : " + digit + " \n");
sll.display();
digit = 5;
print(" Add digit : " + digit + " \n");
sll.display();
}
}``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````/*
Swift 4 Program for
Add the given digit to a number stored in a linked list
*/
{
var data: Int;
init(_ data: Int)
{
self.data = data;
self.next = nil;
}
};
class SingleLL
{
init()
{
}
{
if (data < 0)
{
print("\n Number is negative : ", data ," ");
return;
}
else if (data > 9)
{
print("\n Two digit number is not allowed : ", data ," ");
return;
}
{
}
else
{
//Find last node
while (temp!.next  != nil)
{
temp = temp!.next;
}
// Append the node at last position
temp!.next = node;
}
}
func display()
{
{
return;
}
while (temp  != nil)
{
{
print(" →", terminator: "");
}
print("", temp!.data, terminator: "");
// Visit to next node
temp = temp!.next;
}
print(" → NULL");
}
{
if (digit < 0 || digit > 9)
{
print("\n Invalid digit : ", digit );
return;
}
{
return;
}
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (temp!.next  != nil)
{
if (temp!.data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp!.next;
}
temp!.data = temp!.data + digit;
if (temp!.data > 9)
{
// When need to update linked list
if (auxiliary == nil)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp!.data = temp!.data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary!.next  != nil)
{
auxiliary!.data = (auxiliary!.data + 1) % 10;
// Visit to next node
auxiliary = auxiliary!.next;
}
}
}
}
func main()
{
// Create a empty linked list
let sll: SingleLL = SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
var digit: Int = 9;
print(" Add digit : ", digit ," ");
sll.display();
digit = 6;
print(" Add digit : ", digit ," ");
sll.display();
digit = 5;
print(" Add digit : ", digit ," ");
sll.display();
}
main();``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````
``````/*
Kotlin Program for
Add the given digit to a number stored in a linked list
*/
{
var data: Int;
constructor(data: Int)
{
this.data = data;
this.next = null;
}
};
class SingleLL
{
constructor()
{
}
{
if (data < 0)
{
print("\n Number is negative : " + data + " \n");
return;
}
else if (data > 9)
{
print("\n Two digit number is not allowed : " + data + " \n");
return;
}
{
}
else
{
//Find last node
while (temp?.next != null)
{
temp = temp.next;
}
// Append the node at last position
temp?.next = node;
}
}
fun display(): Unit
{
{
return;
}
while (temp != null)
{
{
print(" →");
}
print(" " + temp.data);
// Visit to next node
temp = temp.next;
}
print(" → NULL\n");
}
{
if (digit < 0 || digit > 9)
{
print("\n Invalid digit : " + digit + "\n");
return;
}
{
return;
}
var auxiliary: LinkNode ? = null;
// Find last node and
// Detect last node which is contain value of less than 9 , // If it is exist
while (temp?.next != null)
{
if (temp.data < 9)
{
auxiliary = temp;
}
// Visit to next node
temp = temp.next;
}
temp?.data = temp!!.data + digit;
if (temp.data > 9)
{
// When need to update linked list
if (auxiliary == null)
{
// When auxiliary is NULL then assign first node to this
// Create a new node
}
// Manage last node
temp.data = temp.data % 10;
// Update the node value from auxiliary to second last node
while (auxiliary?.next != null)
{
auxiliary.data = (auxiliary.data + 1) % 10;
// Visit to next node
auxiliary = auxiliary.next;
}
}
}
}
fun main(args: Array < String > ): Unit
{
// Create a empty linked list
var sll: SingleLL = SingleLL();
//  9 → 9 → 9 → 8 → 9 → NULL
sll.display();
var digit: Int = 9;
print(" Add digit : " + digit + " \n");
sll.display();
digit = 6;
print(" Add digit : " + digit + " \n");
sll.display();
digit = 5;
print(" Add digit : " + digit + " \n");
sll.display();
}``````

Output

`````` 9 → 9 → 9 → 8 → 9 → NULL
9 → 9 → 9 → 9 → 8 → NULL
1 → 0 → 0 → 0 → 0 → 4 → NULL
1 → 0 → 0 → 0 → 0 → 9 → NULL``````

Comment

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.