#Linked lists: Project
1 messages ยท Page 1 of 1 (latest)
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
Here is an AI assisted attempt to answer your question ๐ค. Maybe it helps! In any case, a human is on the way ๐. To continue talking to the AI, you can use </chatgpt:1108714622413963314>.
contains a list of names and their corresponding coordinates. The program will then search for each name in the linked list and display the area of each coordinate.
Here's an example implementation in Python:
class Node:
def __init__(self, name, x, y):
self.name = name
self.x = x
self.y = y
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def insert(self, name, x, y):
new_node = Node(name, x, y)
if not self.head:
self.head = new_node
else:
current = self.head
while current.next:
current = current.next
current.next = new_node
def display_names(self):
current = self.head
while current:
print(current.name)
current = current.next
def read_coordinates(file_name):
linked_list = LinkedList()
with open(file_name, 'r') as file:
for line in file:
data = line.strip().split(',')
name = data[0]
x = float(data[1])
y = float(data[2])
linked_list.insert(name, x, y)
return linked_list
def read_search_names(file_name):
search_names = []
with open(file_name, 'r') as file:
for line in file:
search_names.append(line.strip())
return search_names
def find_area(linked_list, search_names):
current_node = linked_list.head
while current_node:
if current_node.name in search_names:
area = current_node.x * current_node.y
print(f"Name: {current_node.name}, Area: {area}")
current_node= current_node.next
# Read coordinates from a file and store them in a linked list
coordinates_list = read_coordinates('coordinates.txt')
# Display names from the linked list
print("Names:")
coordinates_list.display_names()
# Read search names from a file
search_names_list = read_search_names('search_names.txt')
# Find the area for each search name in the linked list
print("\nAreas:")
find_area(coordinates_list, search_names_list)