def testOrderedList(): ol = OrderedList() while True: print ("Choose operation: ") print (" 1 - Add(data)\n", "2 - Pop()\n", "3 - Search(key)\n", "4 - Remove(data)\n", "5 - Size()\n", "6 - Pop(pos)\n", "7 - exit()\n", ) choice = input() if choice == '1': ol = add(ol) ol.__str__() elif choice == '2': ol = pop(ol) ol.__str__() elif choice == '3': search(ol) ol.__str__() elif choice == '4': ol = remove(ol) ol.__str__() elif choice == '5': print ("Size of list: %d" % ol.size()) ol.__str__() elif choice == '6': ol = popPos(ol) ol.__str__() elif choice == '7': break else: print ("Bad Choice - choose from valid options")
def testOrderedList(): ol = OrderedList() while True: print("Choose operation: ") print( " 1 - Add(data)\n", "2 - Pop()\n", "3 - Search(key)\n", "4 - Remove(data)\n", "5 - Size()\n", "6 - Pop(pos)\n", "7 - exit()\n", ) choice = input() if choice == '1': ol = add(ol) ol.__str__() elif choice == '2': ol = pop(ol) ol.__str__() elif choice == '3': search(ol) ol.__str__() elif choice == '4': ol = remove(ol) ol.__str__() elif choice == '5': print("Size of list: %d" % ol.size()) ol.__str__() elif choice == '6': ol = popPos(ol) ol.__str__() elif choice == '7': break else: print("Bad Choice - choose from valid options")
from OrderedList import OrderedList def print_list(ol): current = ol.head while current != None: print(current.get_data(), end=" ") current = current.get_next() print() ol = OrderedList() for i in range(10, 0, -1): ol.add(i) ol.add(0) print_list(ol) print('Size of the list: %d' % ol.size()) print('Removing 5 from the list: %s' % ol.remove(5)) print_list(ol) for i in range(-1, 12): print('Is %d in the list? %s' % (i, ol.search(i))) print('Is 300 in the list? %s' % ol.search(300))