The assignment seems simple to understand, but it is hard to write down code that follows the instructions. This focuses more onto designing Trees that inherit a main method and to manipulate the Trees that carry out certain tasks, or raise Exceptions in case something goes wrong.
Example code in the Week 7 CSC Lab(This is a length function in CSC Labs):
def __len__(self):
""" Return the number of elements in this linked list. """
counter = 0 # Start an accumulator here
temp_list = [] # create an empty list to add things
while not self.empty:
temp_list.append(self.item) # Add the item into new list that was created
self.decapitate() # Remove the old list away from the new list
counter += 1 # Keep going/adding until while loop reaches false
while temp_list != []:
self.prepend(temp_list[-1])
temp_list.pop(-1)
return counter
Me and my partner used this code as an example to take a list of numbers given to us, and we created a new list, add/appended items and cut down the list one element by one element as a new list extends itself. I was able to show my understanding by practice. For each element, a value exists and I have learned how to create a copy of a list by creating a new list, appending it, then cutting down the old list until the new list only existed. Finally, returns number of elements of this list.
This image was from the CS Website and Wikepedia using examples on Linked Lists
It doesn't make any difference that this week was more based towards Linked Structures and Trees with an arity of one, creating a series of links towards the node. I have been reading the computer science websites on how to construct Linked Lists and I am currently focusing on the applications and uses for the Lists.
No comments:
Post a Comment