class
Node {
int
data;
Node next;
Node prev;
Node(
int
val) {
data = val;
next =
null
;
prev =
null
;
}
}
public
class
Main {
static
int
[] findSmallestProductPair(Node head) {
int
minProduct = Integer.MAX_VALUE;
Node firstNode =
null
;
Node secondNode =
null
;
Node current = head;
while
(current !=
null
) {
Node temp = current.next;
while
(temp !=
null
) {
int
product = current.data * temp.data;
if
(product < minProduct) {
minProduct = product;
firstNode = current;
secondNode = temp;
}
temp = temp.next;
}
current = current.next;
}
return
new
int
[]{firstNode.data, secondNode.data};
}
static
void
displayList(Node head) {
Node current = head;
while
(current !=
null
) {
System.out.print(current.data);
if
(current.next !=
null
) {
System.out.print(
" <-> "
);
}
current = current.next;
}
System.out.println(
" -> NULL"
);
}
public
static
void
main(String[] args) {
Node head =
new
Node(
4
);
head.next =
new
Node(
6
);
head.next.prev = head;
head.next.next =
new
Node(
3
);
head.next.next.prev = head.next;
head.next.next.next =
new
Node(
1
);
head.next.next.next.prev = head.next.next;
head.next.next.next.next =
new
Node(
2
);
head.next.next.next.next.prev = head.next.next.next;
int
[] result = findSmallestProductPair(head);
System.out.println(
"Output: "
+ result[
0
] +
" and "
+ result[
1
]);
}
}