<script>
class Node {
constructor() {
this
.data = 0;
this
.next =
null
;
}
}
function
printMinMax(head) {
if
(head ==
null
) {
return
;
}
var
current;
current = head;
var
min = Number.MAX_VALUE, max = Number.MIN_VALUE;
while
(current.next != head) {
if
(current.data < min) {
min = current.data;
}
if
(current.data > max) {
max = current.data;
}
current = current.next;
}
document.write(
"<br/>Minimum = "
+ min +
", Maximum = "
+ max);
}
function
insertNode(head , data) {
var
current = head;
var
newNode =
new
Node();
if
(newNode ==
null
) {
document.write(
"<br/>Memory Error\n"
);
return
null
;
}
newNode.data = data;
if
(head ==
null
) {
newNode.next = newNode;
head = newNode;
return
head;
}
else
{
while
(current.next != head) {
current = current.next;
}
newNode.next = head;
current.next = newNode;
}
return
head;
}
function
displayList(head) {
var
current = head;
if
(head ==
null
) {
document.write(
"<br/>Display List is empty<br/>"
);
return
;
}
else
{
do
{
document.write(current.data+
" "
);
current = current.next;
}
while
(current != head);
}
}
var
Head =
null
;
Head = insertNode(Head, 99);
Head = insertNode(Head, 11);
Head = insertNode(Head, 22);
Head = insertNode(Head, 33);
Head = insertNode(Head, 44);
Head = insertNode(Head, 55);
Head = insertNode(Head, 66);
document.write(
"Initial List: "
);
displayList(Head);
printMinMax(Head);
</script>