Код на языке Python:
class Node:
def __init__(self, value):
self.value = value
self.next = None
def add_node_to_start(head, value):
new_node = Node(value)
new_node.next = head
head = new_node
return head
def find_max_node(head):
max_value = float('-inf')
current = head
while current is not None:
if current.value > max_value:
max_value = current.value
current = current.next
return max_value
head = Node(1)
node2 = Node(2.5)
node3 = Node(3.4)
head.next = node2
node2.next = node3
head = add_node_to_start(head, 0)
max_value = find_max_node(head)
print("Max: ", max_value)
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Код на языке Python:
class Node:
def __init__(self, value):
self.value = value
self.next = None
def add_node_to_start(head, value):
new_node = Node(value)
new_node.next = head
head = new_node
return head
def find_max_node(head):
max_value = float('-inf')
current = head
while current is not None:
if current.value > max_value:
max_value = current.value
current = current.next
return max_value
head = Node(1)
node2 = Node(2.5)
node3 = Node(3.4)
head.next = node2
node2.next = node3
head = add_node_to_start(head, 0)
max_value = find_max_node(head)
print("Max: ", max_value)