Run ❯
Get your
own
website
×
Change Orientation
Change Theme, Dark/Light
Go to Spaces
Python
C
Java
class Node: def __init__(self, data): self.data = data self.next = None def findLowestValue(head): minValue = head.data currentNode = head.next while currentNode: if currentNode.data < minValue: minValue = currentNode.data currentNode = currentNode.next return minValue node1 = Node(7) node2 = Node(11) node3 = Node(3) node4 = Node(2) node5 = Node(9) node1.next = node2 node2.next = node3 node3.next = node4 node4.next = node5 print("The lowest value in the linked list is:", findLowestValue(node1)) #Python
#include
#include
struct Node { int data; struct Node* next; }; int findLowestValue(struct Node* head) { int minValue = head->data; struct Node* currentNode = head->next; while (currentNode) { if (currentNode->data < minValue) { minValue = currentNode->data; } currentNode = currentNode->next; } return minValue; } int main() { struct Node* node1 = (struct Node*) malloc(sizeof(struct Node)); struct Node* node2 = (struct Node*) malloc(sizeof(struct Node)); struct Node* node3 = (struct Node*) malloc(sizeof(struct Node)); struct Node* node4 = (struct Node*) malloc(sizeof(struct Node)); struct Node* node5 = (struct Node*) malloc(sizeof(struct Node)); node1->data = 7; node2->data = 11; node3->data = 3; node4->data = 2; node5->data = 9; node1->next = node2; node2->next = node3; node3->next = node4; node4->next = node5; node5->next = NULL; printf("The lowest value in the linked list is: %d\n", findLowestValue(node1)); return 0; } //C
public class Main { public static void main(String[] args) { Node node1 = new Node(7); Node node2 = new Node(11); Node node3 = new Node(3); Node node4 = new Node(2); Node node5 = new Node(9); node1.next = node2; node2.next = node3; node3.next = node4; node4.next = node5; System.out.println("The lowest value in the linked list is: " + findLowestValue(node1)); } public static int findLowestValue(Node head) { int minValue = head.data; Node currentNode = head.next; while (currentNode != null) { if (currentNode.data < minValue) { minValue = currentNode.data; } currentNode = currentNode.next; } return minValue; } } class Node { int data; Node next; public Node(int data) { this.data = data; this.next = null; } } //Java
Python result:
C result:
Java result:
The lowest value in the linked list is: 2
The lowest value in the linked list is: 2
The lowest value in the linked list is: 2