# Bitonic point in the given linked list

Here given code implementation process.

``````// C Program
// Bitonic point in the given 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(" →");
}
printf(" %d", temp->data);
//visit to next node
temp = temp->next;
}
printf(" → NULL");
}
//Find a valid bitonic point in given linked list node sequence
{
//get first node
if (point == NULL || point->next == NULL || point->data > point->next->data || point->next->next == NULL)
{
//if given bitonic sequence are invalid
printf("\n Bitonic point not exist\n");
}
else
{
struct Node *result = NULL;
// increasing sequence
while (point != NULL && result == NULL && point->next != NULL)
{
if (point->data > point->next->data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point->next;
}
if (result != NULL && point != NULL)
{
// Check decreasing sequence
while (point != NULL && result != NULL && point->next != NULL)
{
if (point->next->data < point->data)
{
point = point->next;
}
else
{
//When bitonic sequence are not valid
result = NULL;
}
}
if (result != NULL)
{
printf("\n Bitonic point : %d\n", result->data);
}
else
{
printf("\n Bitonic point not exist\n");
}
}
else
{
//When no valid endpoint in increasing bitonic sequence
printf("\n Bitonic point not exist\n");
}
}
}
int main()
{
struct Node *list1 = NULL;
struct Node *list2 = NULL;
struct Node *list3 = NULL;
struct Node *list4 = NULL;
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
insert( &list1, 2);
insert( &list1, 4);
insert( &list1, 8);
insert( &list1, 9);
insert( &list1, 7);
insert( &list1, 5);
insert( &list1, 3);
//  1 → 2 → 3 → 4 → NULL
insert( &list2, 1);
insert( &list2, 2);
insert( &list2, 3);
insert( &list2, 4);
//  1 → 2 → 3 → 4  → 1 → NULL
insert( &list3, 1);
insert( &list3, 2);
insert( &list3, 3);
insert( &list3, 4);
insert( &list3, 1);
//  1 → 2 → 3 → 4  → 4 → NULL
insert( &list4, 1);
insert( &list4, 2);
insert( &list4, 3);
insert( &list4, 4);
insert( &list4, 4);
//Test case
bitonic_point(list1);
bitonic_point(list2);
bitonic_point(list3);
bitonic_point(list4);
return 0;
}``````

#### Output

`````` Linked List  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````// Java Program
// Bitonic point in the given 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)
{
{
System.out.print(" →");
}
System.out.print(" " + temp.data);
//visit to next node
temp = temp.next;
}
System.out.print(" → NULL");
}
//Find a valid bitonic point in given linked list node sequence
public void bitonic_point()
{
//get first node
this.display();
if (point == null || point.next == null || point.data > point.next.data || point.next.next == null)
{
//if given bitonic sequence are invalid
System.out.print("\n Bitonic point not exist\n");
}
else
{
Node result = null;
// increasing sequence
while (point != null && result == null && point.next != null)
{
if (point.data > point.next.data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point.next;
}
if (result != null && point != null)
{
// Check decreasing sequence
while (point != null && result != null && point.next != null)
{
if (point.next.data < point.data)
{
point = point.next;
}
else
{
//When bitonic sequence are not valid
result = null;
}
}
if (result != null)
{
System.out.print("\n Bitonic point : " + result.data + "\n");
}
else
{
System.out.print("\n Bitonic point not exist\n");
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
System.out.print("\n Bitonic point not exist\n");
}
}
}
public static void main(String[] args)
{
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2);
list1.insert(4);
list1.insert(8);
list1.insert(9);
list1.insert(7);
list1.insert(5);
list1.insert(3);
//  1 → 2 → 3 → 4 → NULL
list2.insert(1);
list2.insert(2);
list2.insert(3);
list2.insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1);
list3.insert(2);
list3.insert(3);
list3.insert(4);
list3.insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1);
list4.insert(2);
list4.insert(3);
list4.insert(4);
list4.insert(4);
//Test case
list1.bitonic_point();
list2.bitonic_point();
list3.bitonic_point();
list4.bitonic_point();
}
}``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````//Include header file
#include <iostream>

using namespace std;

// C++ Program
// Bitonic point in the given 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)
{
{
cout << " →";
}
cout << " " << temp->data;
//visit to next node
temp = temp->next;
}
cout << " → NULL";
}
//Find a valid bitonic point in given linked list node sequence
void bitonic_point()
{
//get first node
cout << "\n Linked List ";
this->display();
if (point == NULL || point->next == NULL || point->data > point->next->data || point->next->next == NULL)
{
//if given bitonic sequence are invalid
cout << "\n Bitonic point not exist\n";
}
else
{
Node *result = NULL;
// increasing sequence
while (point != NULL && result == NULL && point->next != NULL)
{
if (point->data > point->next->data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point->next;
}
if (result != NULL && point != NULL)
{
// Check decreasing sequence
while (point != NULL && result != NULL && point->next != NULL)
{
if (point->next->data < point->data)
{
point = point->next;
}
else
{
//When bitonic sequence are not valid
result = NULL;
}
}
if (result != NULL)
{
cout << "\n Bitonic point : " << result->data << "\n";
}
else
{
cout << "\n Bitonic point not exist\n";
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
cout << "\n Bitonic point not exist\n";
}
}
}
};
int main()
{
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2);
list1.insert(4);
list1.insert(8);
list1.insert(9);
list1.insert(7);
list1.insert(5);
list1.insert(3);
//  1 → 2 → 3 → 4 → NULL
list2.insert(1);
list2.insert(2);
list2.insert(3);
list2.insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1);
list3.insert(2);
list3.insert(3);
list3.insert(4);
list3.insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1);
list4.insert(2);
list4.insert(3);
list4.insert(4);
list4.insert(4);
//Test case
list1.bitonic_point();
list2.bitonic_point();
list3.bitonic_point();
list4.bitonic_point();
return 0;
}``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````//Include namespace system
using System;
// C# Program
// Bitonic point in the given 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)
{
{
Console.Write(" →");
}
Console.Write(" " + temp.data);
//visit to next node
temp = temp.next;
}
Console.Write(" → NULL");
}
//Find a valid bitonic point in given linked list node sequence
public void bitonic_point()
{
//get first node
this.display();
if (point == null || point.next == null || point.data > point.next.data || point.next.next == null)
{
//if given bitonic sequence are invalid
Console.Write("\n Bitonic point not exist\n");
}
else
{
Node result = null;
// increasing sequence
while (point != null && result == null && point.next != null)
{
if (point.data > point.next.data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point.next;
}
if (result != null && point != null)
{
// Check decreasing sequence
while (point != null && result != null && point.next != null)
{
if (point.next.data < point.data)
{
point = point.next;
}
else
{
//When bitonic sequence are not valid
result = null;
}
}
if (result != null)
{
Console.Write("\n Bitonic point : " + result.data + "\n");
}
else
{
Console.Write("\n Bitonic point not exist\n");
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
Console.Write("\n Bitonic point not exist\n");
}
}
}
public static void Main(String[] args)
{
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2);
list1.insert(4);
list1.insert(8);
list1.insert(9);
list1.insert(7);
list1.insert(5);
list1.insert(3);
//  1 → 2 → 3 → 4 → NULL
list2.insert(1);
list2.insert(2);
list2.insert(3);
list2.insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1);
list3.insert(2);
list3.insert(3);
list3.insert(4);
list3.insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1);
list4.insert(2);
list4.insert(3);
list4.insert(4);
list4.insert(4);
//Test case
list1.bitonic_point();
list2.bitonic_point();
list3.bitonic_point();
list4.bitonic_point();
}
}``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````<?php
// Php Program
// Bitonic point in the given 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)
{
{
echo " →";
}
echo " ". \$temp->data;
//visit to next node
\$temp = \$temp->next;
}
echo " → NULL";
}
//Find a valid bitonic point in given linked list node sequence
public	function bitonic_point()
{
//get first node
\$this->display();
if (\$point == null || \$point->next == null || \$point->data > \$point->next->data || \$point->next->next == null)
{
//if given bitonic sequence are invalid
echo "\n Bitonic point not exist\n";
}
else
{
\$result = null;
// increasing sequence
while (\$point != null && \$result == null && \$point->next != null)
{
if (\$point->data > \$point->next->data)
{
//This is endpoint of increasing sequence
\$result = \$point;
}
//visit to next node
\$point = \$point->next;
}
if (\$result != null && \$point != null)
{
// Check decreasing sequence
while (\$point != null && \$result != null && \$point->next != null)
{
if (\$point->next->data < \$point->data)
{
\$point = \$point->next;
}
else
{
//When bitonic sequence are not valid
\$result = null;
}
}
if (\$result != null)
{
echo "\n Bitonic point : ". \$result->data ."\n";
}
else
{
echo "\n Bitonic point not exist\n";
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
echo "\n Bitonic point not exist\n";
}
}
}
}

function main()
{
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
\$list1->insert(2);
\$list1->insert(4);
\$list1->insert(8);
\$list1->insert(9);
\$list1->insert(7);
\$list1->insert(5);
\$list1->insert(3);
//  1 → 2 → 3 → 4 → NULL
\$list2->insert(1);
\$list2->insert(2);
\$list2->insert(3);
\$list2->insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
\$list3->insert(1);
\$list3->insert(2);
\$list3->insert(3);
\$list3->insert(4);
\$list3->insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
\$list4->insert(1);
\$list4->insert(2);
\$list4->insert(3);
\$list4->insert(4);
\$list4->insert(4);
//Test case
\$list1->bitonic_point();
\$list2->bitonic_point();
\$list3->bitonic_point();
\$list4->bitonic_point();
}
main();``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````// Node Js Program
// Bitonic point in the given 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)
{
{
process.stdout.write(" →");
}
process.stdout.write(" " + temp.data);
//visit to next node
temp = temp.next;
}
process.stdout.write(" → NULL");
}
//Find a valid bitonic point in given linked list node sequence
bitonic_point()
{
//get first node
this.display();
if (point == null || point.next == null || point.data > point.next.data || point.next.next == null)
{
//if given bitonic sequence are invalid
process.stdout.write("\n Bitonic point not exist\n");
}
else
{
var result = null;
// increasing sequence
while (point != null && result == null && point.next != null)
{
if (point.data > point.next.data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point.next;
}
if (result != null && point != null)
{
// Check decreasing sequence
while (point != null && result != null && point.next != null)
{
if (point.next.data < point.data)
{
point = point.next;
}
else
{
//When bitonic sequence are not valid
result = null;
}
}
if (result != null)
{
process.stdout.write("\n Bitonic point : " + result.data + "\n");
}
else
{
process.stdout.write("\n Bitonic point not exist\n");
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
process.stdout.write("\n Bitonic point not exist\n");
}
}
}
}

function main()
{
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2);
list1.insert(4);
list1.insert(8);
list1.insert(9);
list1.insert(7);
list1.insert(5);
list1.insert(3);
//  1 → 2 → 3 → 4 → NULL
list2.insert(1);
list2.insert(2);
list2.insert(3);
list2.insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1);
list3.insert(2);
list3.insert(3);
list3.insert(4);
list3.insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1);
list4.insert(2);
list4.insert(3);
list4.insert(4);
list4.insert(4);
//Test case
list1.bitonic_point();
list2.bitonic_point();
list3.bitonic_point();
list4.bitonic_point();
}
main();``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````#  Python 3 Program
#  Bitonic point in the given 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) :
print(" →", end = "")

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

print(" → NULL", end = "")

# Find a valid bitonic point in given linked list node sequence
def bitonic_point(self) :
# get first node
print("\n Linked List ", end = "")
self.display()
if (point == None or point.next == None or point.data > point.next.data or point.next.next == None) :
# if given bitonic sequence are invalid
print("\n Bitonic point not exist\n", end = "")
else :
result = None
#  increasing sequence
while (point != None and result == None and point.next != None) :
if (point.data > point.next.data) :
# This is endpoint of increasing sequence
result = point

# visit to next node
point = point.next

if (result != None and point != None) :
#  Check decreasing sequence
while (point != None and result != None and point.next != None) :
if (point.next.data < point.data) :
point = point.next
else :
# When bitonic sequence are not valid
result = None

if (result != None) :
print("\n Bitonic point : ", result.data ,"\n", end = "")
else :
print("\n Bitonic point not exist\n", end = "")

else :
# When no valid bitonic point in increasing bitonic sequence
print("\n Bitonic point not exist\n", end = "")

def main() :
#   2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2)
list1.insert(4)
list1.insert(8)
list1.insert(9)
list1.insert(7)
list1.insert(5)
list1.insert(3)
#   1 → 2 → 3 → 4 → NULL
list2.insert(1)
list2.insert(2)
list2.insert(3)
list2.insert(4)
#   1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1)
list3.insert(2)
list3.insert(3)
list3.insert(4)
list3.insert(1)
#   1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1)
list4.insert(2)
list4.insert(3)
list4.insert(4)
list4.insert(4)
# Test case
list1.bitonic_point()
list2.bitonic_point()
list3.bitonic_point()
list4.bitonic_point()

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

#### Output

`````` Linked List
Linked List :   2 →  4 →  8 →  9 →  7 →  5 →  3 → NULL
Bitonic point :  9

Linked List :   1 →  2 →  3 →  4 → NULL
Bitonic point not exist

Linked List :   1 →  2 →  3 →  4 →  1 → NULL
Bitonic point :  4

Linked List :   1 →  2 →  3 →  4 →  4 → NULL
Bitonic point not exist``````
``````#  Ruby Program
#  Bitonic point in the given 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)

print(" →")
end
print(" ", temp.data)
# visit to next node
temp = temp.next
end
print(" → NULL")
end
# Find a valid bitonic point in given linked list node sequence
def bitonic_point()

# get first node
self.display()
if (point == nil || point.next == nil || point.data > point.next.data || point.next.next == nil)

# if given bitonic sequence are invalid
print("\n Bitonic point not exist\n")
else

result = nil
#  increasing sequence
while (point != nil && result == nil && point.next != nil)

if (point.data > point.next.data)

# This is endpoint of increasing sequence
result = point
end
# visit to next node
point = point.next
end
if (result != nil && point != nil)

#  Check decreasing sequence
while (point != nil && result != nil && point.next != nil)

if (point.next.data < point.data)

point = point.next
else

# When bitonic sequence are not valid
result = nil
end
end
if (result != nil)

print("\n Bitonic point : ", result.data ,"\n")
else

print("\n Bitonic point not exist\n")
end
else

# When no valid bitonic point in increasing bitonic sequence
print("\n Bitonic point not exist\n")
end
end
end
end
def main()

#   2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2)
list1.insert(4)
list1.insert(8)
list1.insert(9)
list1.insert(7)
list1.insert(5)
list1.insert(3)
#   1 → 2 → 3 → 4 → NULL
list2.insert(1)
list2.insert(2)
list2.insert(3)
list2.insert(4)
#   1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1)
list3.insert(2)
list3.insert(3)
list3.insert(4)
list3.insert(1)
#   1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1)
list4.insert(2)
list4.insert(3)
list4.insert(4)
list4.insert(4)
# Test case
list1.bitonic_point()
list2.bitonic_point()
list3.bitonic_point()
list4.bitonic_point()
end
main()``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist
``````
``````// Scala Program
// Bitonic point in the given 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)
{
{
print(" →");
}
print(" " + temp.data);
//visit to next node
temp = temp.next;
}
print(" → NULL");
}
//Find a valid bitonic point in given linked list node sequence
def bitonic_point(): Unit = {
//get first node
this.display();
if (point == null || point.next == null || point.data > point.next.data || point.next.next == null)
{
//if given bitonic sequence are invalid
print("\n Bitonic point not exist\n");
}
else
{
var result: Node = null;
// increasing sequence
while (point != null && result == null && point.next != null)
{
if (point.data > point.next.data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point.next;
}
if (result != null && point != null)
{
// Check decreasing sequence
while (point != null && result != null && point.next != null)
{
if (point.next.data < point.data)
{
point = point.next;
}
else
{
//When bitonic sequence are not valid
result = null;
}
}
if (result != null)
{
print("\n Bitonic point : " + result.data + "\n");
}
else
{
print("\n Bitonic point not exist\n");
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
print("\n Bitonic point not exist\n");
}
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2);
list1.insert(4);
list1.insert(8);
list1.insert(9);
list1.insert(7);
list1.insert(5);
list1.insert(3);
//  1 → 2 → 3 → 4 → NULL
list2.insert(1);
list2.insert(2);
list2.insert(3);
list2.insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1);
list3.insert(2);
list3.insert(3);
list3.insert(4);
list3.insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1);
list4.insert(2);
list4.insert(3);
list4.insert(4);
list4.insert(4);
//Test case
list1.bitonic_point();
list2.bitonic_point();
list3.bitonic_point();
list4.bitonic_point();
}
}``````

#### Output

`````` Linked List
Linked List :  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
Bitonic point : 9

Linked List :  1 → 2 → 3 → 4 → NULL
Bitonic point not exist

Linked List :  1 → 2 → 3 → 4 → 1 → NULL
Bitonic point : 4

Linked List :  1 → 2 → 3 → 4 → 4 → NULL
Bitonic point not exist``````
``````// Swift Program
// Bitonic point in the given 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)
{
{
print(" →", terminator: "");
}
print(" ", temp!.data, terminator: "");
//visit to next node
temp = temp!.next;
}
print(" → NULL", terminator: "");
}
//Find a valid bitonic point in given linked list node sequence
func bitonic_point()
{
//get first node
print("\n Linked List ", terminator: "");
self.display();
if (point == nil || point!.next == nil || point!.data > point!.next!.data || point!.next!.next == nil)
{
//if given bitonic sequence are invalid
print("\n Bitonic point not exist\n", terminator: "");
}
else
{
var result: Node? = nil;
// increasing sequence
while (point != nil && result == nil && point!.next != nil)
{
if (point!.data > point!.next!.data)
{
//This is endpoint of increasing sequence
result = point;
}
//visit to next node
point = point!.next;
}
if (result != nil && point != nil)
{
// Check decreasing sequence
while (point != nil && result != nil && point!.next != nil)
{
if (point!.next!.data < point!.data)
{
point = point!.next;
}
else
{
//When bitonic sequence are not valid
result = nil;
}
}
if (result != nil)
{
print("\n Bitonic point : ", result!.data ,"\n", terminator: "");
}
else
{
print("\n Bitonic point not exist\n", terminator: "");
}
}
else
{
//When no valid bitonic point in increasing bitonic sequence
print("\n Bitonic point not exist\n", terminator: "");
}
}
}
}
func main()
{
//  2 → 4 → 8 → 9 → 7 → 5 → 3 → NULL
list1.insert(2);
list1.insert(4);
list1.insert(8);
list1.insert(9);
list1.insert(7);
list1.insert(5);
list1.insert(3);
//  1 → 2 → 3 → 4 → NULL
list2.insert(1);
list2.insert(2);
list2.insert(3);
list2.insert(4);
//  1 → 2 → 3 → 4  → 1 → NULL
list3.insert(1);
list3.insert(2);
list3.insert(3);
list3.insert(4);
list3.insert(1);
//  1 → 2 → 3 → 4  → 4 → NULL
list4.insert(1);
list4.insert(2);
list4.insert(3);
list4.insert(4);
list4.insert(4);
//Test case
list1.bitonic_point();
list2.bitonic_point();
list3.bitonic_point();
list4.bitonic_point();
}
main();``````

#### Output

`````` Linked List
Linked List :   2 →  4 →  8 →  9 →  7 →  5 →  3 → NULL
Bitonic point :  9

Linked List :   1 →  2 →  3 →  4 → NULL
Bitonic point not exist

Linked List :   1 →  2 →  3 →  4 →  1 → NULL
Bitonic point :  4

Linked List :   1 →  2 →  3 →  4 →  4 → NULL
Bitonic point not exist``````

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