运行 ❯
获取您
的
网站
×
更改方向
更改主题,深色/浅色
前往 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 <stdio.h> #include <stdlib.h> 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 结果
C 结果
Java 结果
链表中的最小值为:2
链表中的最小值为:2
链表中的最小值为:2