from linked_list import *

class SortedList(LinkedList):
    '''A sorted list.'''
    
    def add(self, item):
        '''Add item to this List where it belongs.'''
        
        # Set prev and curr to the items before and after where item belongs.
        curr = self.head
        prev = None
        while curr != None and curr.data < item:
            prev = curr
            curr = curr.next
    
        temp = Node(item)
        temp.next = curr
        if prev is None:
            # new item goes at the front
            self.head = temp
        else:
            prev.next = temp
