# Find fractional node in linked list

Here given code implementation process.

``````// C Program
// Find fractional node in linked list
#include <stdio.h>
//for malloc function
#include <stdlib.h>

//Create structure
struct Node
{
int data;
struct Node *next;
};
struct Node *tail = NULL;
void insert(int value)
{
//Create dynamic node
struct Node *node = (struct Node *) malloc(sizeof(struct Node));
if (node == NULL)
{
printf("Memory overflow\n");
}
else
{
node->data = value;
node->next = NULL;
{
tail = node;
}
else
{
tail->next = node;
tail = node;
}
}
}
void display()
{
{
return;
}
while (temp != NULL)
{
printf("  %d", temp->data);
temp = temp->next;
{
//When loop existing
return;
}
}
}
//Find fractional node using k value
void find_fractional_node(int k)
{
{
printf("\nFractional of divisible %d are not exist", k);
return;
}
//Define Useful resultant variable
struct Node *result = NULL;
int counter = 0;
//Sum of all nodes
while (temp != NULL)
{
if (counter % k == 0)
{
if (result == NULL)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result->next;
}
}
//visit to next node
temp = temp->next;
counter++;
}
printf("\n Fractional of divisible %d is : %d", k, result->data);
}
int main()
{
insert(8);
insert(2);
insert(9);
insert(4);
insert(7);
insert(5);
insert(3);
display();
//Fractional_node
find_fractional_node(2);
find_fractional_node(3);
find_fractional_node(11);
return 0;
}``````

#### Output

`````` Linked List :  8  2  9  4  7  5  3
Fractional of divisible 2 is : 4
Fractional of divisible 3 is : 9
Fractional of divisible 11 is : 8``````
``````// Java Program
// Find fractional node 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 constructors
{
this.tail = null;
}
//insert node at last of linke list
public void insert(int value)
{
//Create a node
Node node = new Node(value);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
public void display()
{
{
while (temp != null)
{
System.out.print(" " + temp.data);
temp = temp.next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
public void find_fractional_node(int k)
{
{
System.out.print("\nFractional node of divisible " + k + " are not exist");
return;
}
//Define Useful resultant variable
Node result = null;
//Counter
int counter = 0;
while (temp != null)
{
if (counter % k == 0)
{
if (result == null)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result.next;
}
}
//visit to next node
temp = temp.next;
counter++;
}
System.out.print("\n Fractional node of divisible " + k + " are : " + result.data);
}
public static void main(String[] args)
{
obj.insert(8);
obj.insert(2);
obj.insert(9);
obj.insert(4);
obj.insert(7);
obj.insert(5);
obj.insert(3);
obj.display();
//Fractional_node
obj.find_fractional_node(2);
obj.find_fractional_node(3);
obj.find_fractional_node(11);
}
}``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````//Include header file
#include <iostream>
using namespace std;

// C++ Program
// Find fractional node 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 constructors
{
this->tail = NULL;
}
//insert node at last of linke list
void insert(int value)
{
//Create a node
Node * node = new Node(value);
{
this->tail = node;
}
else
{
this->tail->next = node;
this->tail = node;
}
}
void display()
{
{
cout << " Linked List :";
while (temp != NULL)
{
cout << " " << temp->data;
temp = temp->next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
void find_fractional_node(int k)
{
{
cout << "\nFractional node of divisible " << k << " are not exist";
return;
}
//Define Useful resultant variable
Node * result = NULL;
//Counter
int counter = 0;
while (temp != NULL)
{
if (counter % k == 0)
{
if (result == NULL)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result->next;
}
}
//visit to next node
temp = temp->next;
counter++;
}
cout << "\n Fractional node of divisible " << k << " are : " << result->data;
}
};
int main()
{
obj.insert(8);
obj.insert(2);
obj.insert(9);
obj.insert(4);
obj.insert(7);
obj.insert(5);
obj.insert(3);
obj.display();
//Fractional_node
obj.find_fractional_node(2);
obj.find_fractional_node(3);
obj.find_fractional_node(11);
return 0;
}``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````//Include namespace system
using System;

// C# Program
// Find fractional node 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 constructors
{
this.tail = null;
}
//insert node at last of linke list
public void insert(int value)
{
//Create a node
Node node = new Node(value);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
public void display()
{
{
while (temp != null)
{
Console.Write(" " + temp.data);
temp = temp.next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
public void find_fractional_node(int k)
{
{
Console.Write("\nFractional node of divisible " + k + " are not exist");
return;
}
//Define Useful resultant variable
Node result = null;
//Counter
int counter = 0;
while (temp != null)
{
if (counter % k == 0)
{
if (result == null)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result.next;
}
}
//visit to next node
temp = temp.next;
counter++;
}
Console.Write("\n Fractional node of divisible " + k + " are : " + result.data);
}
public static void Main(String[] args)
{
obj.insert(8);
obj.insert(2);
obj.insert(9);
obj.insert(4);
obj.insert(7);
obj.insert(5);
obj.insert(3);
obj.display();
//Fractional_node
obj.find_fractional_node(2);
obj.find_fractional_node(3);
obj.find_fractional_node(11);
}
}``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````<?php
// Php Program
// Find fractional node in linked list

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

function __construct(\$data)
{
//set node value
\$this->data = \$data;
\$this->next = null;
}
}
{
public \$tail;
//Class constructors
function __construct()
{
\$this->tail = null;
}
//insert node at last of linke list
public	function insert(\$value)
{
//Create a node
\$node = new Node(\$value);
{
\$this->tail = \$node;
}
else
{
\$this->tail->next = \$node;
\$this->tail = \$node;
}
}
public	function display()
{
{
while (\$temp != null)
{
echo " ". \$temp->data;
\$temp = \$temp->next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
public	function find_fractional_node(\$k)
{
{
echo "\nFractional node of divisible ". \$k ." are not exist";
return;
}
//Define Useful resultant variable
\$result = null;
//Counter
\$counter = 0;
while (\$temp != null)
{
if (\$counter % \$k == 0)
{
if (\$result == null)
{
//Get first node of linked list
}
else
{
//visit to next node
\$result = \$result->next;
}
}
//visit to next node
\$temp = \$temp->next;
\$counter++;
}
echo "\n Fractional node of divisible ". \$k ." are : ". \$result->data;
}
}

function main()
{
\$obj->insert(8);
\$obj->insert(2);
\$obj->insert(9);
\$obj->insert(4);
\$obj->insert(7);
\$obj->insert(5);
\$obj->insert(3);
\$obj->display();
//Fractional_node
\$obj->find_fractional_node(2);
\$obj->find_fractional_node(3);
\$obj->find_fractional_node(11);
}
main();``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````// Node Js Program
// Find fractional node in linked list

class Node
{
constructor(data)
{
//set node value
this.data = data;
this.next = null;
}
}
{
//Class constructors
constructor()
{
this.tail = null;
}
//insert node at last of linke list
insert(value)
{
//Create a node
var node = new Node(value);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
display()
{
{
while (temp != null)
{
process.stdout.write(" " + temp.data);
temp = temp.next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
find_fractional_node(k)
{
{
process.stdout.write("\nFractional node of divisible " + k + " are not exist");
return;
}
//Define Useful resultant variable
var result = null;
//Counter
var counter = 0;
while (temp != null)
{
if (counter % k == 0)
{
if (result == null)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result.next;
}
}
//visit to next node
temp = temp.next;
counter++;
}
process.stdout.write("\n Fractional node of divisible " + k + " are : " + result.data);
}
}

function main()
{
obj.insert(8);
obj.insert(2);
obj.insert(9);
obj.insert(4);
obj.insert(7);
obj.insert(5);
obj.insert(3);
obj.display();
//Fractional_node
obj.find_fractional_node(2);
obj.find_fractional_node(3);
obj.find_fractional_node(11);
}
main();``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````#  Python 3 Program
#  Find fractional node in linked list

class Node :

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

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

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

def display(self) :
print(" Linked List :", end = "")
while (temp != None) :
print(" ", temp.data, end = "")
temp = temp.next
# avoid loop
return

else :
print("Empty Linked List", end = "")

# Find fractional node using k value
def find_fractional_node(self, k) :
print("\nFractional node of divisible ", k ," are not exist", end = "")
return

# Define Useful resultant variable
result = None
# Counter
counter = 0
while (temp != None) :
if (counter % k == 0) :
if (result == None) :
# Get first node of linked list
else :
# visit to next node
result = result.next

# visit to next node
temp = temp.next
counter += 1

print("\n Fractional node of divisible ", k ," are : ", result.data, end = "")

def main() :
# insert element of linked list
obj.insert(8)
obj.insert(2)
obj.insert(9)
obj.insert(4)
obj.insert(7)
obj.insert(5)
obj.insert(3)
obj.display()
# Fractional_node
obj.find_fractional_node(2)
obj.find_fractional_node(3)
obj.find_fractional_node(11)

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

#### Output

`````` Linked List :  8  2  9  4  7  5  3
Fractional node of divisible  2  are :  4
Fractional node of divisible  3  are :  9
Fractional node of divisible  11  are :  8``````
``````#  Ruby Program
#  Find fractional node 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 constructors
def initialize()

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

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

self.tail = node
else

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

while (temp != nil)

print(" ", temp.data)
temp = temp.next

# avoid loop
return
end
end
else

end
end
# Find fractional node using k value
def find_fractional_node(k)

print("\nFractional node of divisible ", k ," are not exist")
return
end
# Define Useful resultant variable
result = nil
# Counter
counter = 0
while (temp != nil)

if (counter % k == 0)

if (result == nil)

# Get first node of linked list
else

# visit to next node
result = result.next
end
end
# visit to next node
temp = temp.next
counter += 1
end
print("\n Fractional node of divisible ", k ," are : ", result.data)
end
end
def main()

# insert element of linked list
obj.insert(8)
obj.insert(2)
obj.insert(9)
obj.insert(4)
obj.insert(7)
obj.insert(5)
obj.insert(3)
obj.display()
# Fractional_node
obj.find_fractional_node(2)
obj.find_fractional_node(3)
obj.find_fractional_node(11)
end
main()``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````// Scala Program
// Find fractional node in linked list

class Node(var data: Int,
var next: Node)
{
def this(data: Int)
{
this(data, null);
}
}
var tail: Node)
{
//Class constructors
def this()
{
this(null, null);
}
//insert node at last of linke list
def insert(value: Int): Unit = {
//Create a node
var node: Node = new Node(value);
{
this.tail = node;
}
else
{
this.tail.next = node;
this.tail = node;
}
}
def display(): Unit = {
{
while (temp != null)
{
print(" " + temp.data);
temp = temp.next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
def find_fractional_node(k: Int): Unit = {
{
print("\nFractional node of divisible " + k + " are not exist");
return;
}
//Define Useful resultant variable
var result: Node = null;
//Counter
var counter: Int = 0;
while (temp != null)
{
if (counter % k == 0)
{
if (result == null)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result.next;
}
}
//visit to next node
temp = temp.next;
counter += 1;
}
print("\n Fractional node of divisible " + k + " are : " + result.data);
}
}
object Main
{
def main(args: Array[String]): Unit = {
obj.insert(8);
obj.insert(2);
obj.insert(9);
obj.insert(4);
obj.insert(7);
obj.insert(5);
obj.insert(3);
obj.display();
//Fractional_node
obj.find_fractional_node(2);
obj.find_fractional_node(3);
obj.find_fractional_node(11);
}
}``````

#### Output

`````` Linked List : 8 2 9 4 7 5 3
Fractional node of divisible 2 are : 4
Fractional node of divisible 3 are : 9
Fractional node of divisible 11 are : 8``````
``````// Swift Program
// Find fractional node 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 constructors
init()
{
self.tail = nil;
}
//insert node at last of linke list
func insert(_ value: Int)
{
//Create a node
let node: Node? = Node(value);
{
self.tail = node;
}
else
{
self.tail!.next = node;
self.tail = node;
}
}
func display()
{
{
print(" Linked List :", terminator: "");
while (temp != nil)
{
print(" ", temp!.data, terminator: "");
temp = temp!.next;
{
//avoid loop
return;
}
}
}
else
{
}
}
//Find fractional node using k value
func find_fractional_node(_ k: Int)
{
{
print("\nFractional node of divisible ", k ," are not exist", terminator: "");
return;
}
//Define Useful resultant variable
var result: Node? = nil;
//Counter
var counter: Int = 0;
while (temp != nil)
{
if (counter % k == 0)
{
if (result == nil)
{
//Get first node of linked list
}
else
{
//visit to next node
result = result!.next;
}
}
//visit to next node
temp = temp!.next;
counter += 1;
}
print("\n Fractional node of divisible ", k ," are : ", result!.data, terminator: "");
}
}
func main()
{
obj.insert(8);
obj.insert(2);
obj.insert(9);
obj.insert(4);
obj.insert(7);
obj.insert(5);
obj.insert(3);
obj.display();
//Fractional_node
obj.find_fractional_node(2);
obj.find_fractional_node(3);
obj.find_fractional_node(11);
}
main();``````

#### Output

`````` Linked List :  8  2  9  4  7  5  3
Fractional node of divisible  2  are :  4
Fractional node of divisible  3  are :  9
Fractional node of divisible  11  are :  8``````

## 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.