compsci-notes-spring-2024/labs/cosc-2436/chapter-4/Python/main.py

36 lines
928 B
Python
Raw Normal View History

from SortedNumberList import SortedNumberList
def main():
# Read the line of input numbers
terms = input().split()
sorted_list = SortedNumberList()
# Insert each value and show the sorted list's contents after each insertion
for term in terms:
number = float(term)
print(f"""List after inserting {number}: """)
sorted_list.insert(number)
print_list(sorted_list)
# Read the input line with numbers to remove
terms = input().split()
for term in terms:
number = float(term)
print(f"""List after removing {number}: """)
sorted_list.remove(number)
print_list(sorted_list)
# Prints the sorted_number_list's contents, in order from head to tail
def print_list(lst):
node = lst.head
while node != None:
print(node.get_data(), end=' ')
node = node.get_next()
print()
if __name__ == '__main__':
main()