Question
In a python program you need to add more methods defined in the UnorderedList ADT (append, index, insert, and printList) as described below: - Implement
In a python program you need to add more methods defined in the UnorderedList ADT (append, index, insert, and printList) as described below:
- Implement the append method to add a new item to the end of the list. It needs the item and returns nothing.
- Implement the index method to return the position of the item in the list. It needs the item and returns the index of the item. You can assume the item is in the list.
- Implement the insert method that inserts a new item to the list at position pos. It needs the position pos and the item, and returns nothing.
- Implement the printList method to print out all items in the list
Sample Output:
54 26 93 17 77 31 89
7
True
3
54 26 15 93 17 77 31 89
54 26 15 17 77 31 89
Test File:
myList = UnorderedList() myList.add(31) myList.add(77) myList.add(17) myList.add(93) myList.add(26) myList.add(54) myList.append(89) myList.printList() print() print(myList.size()) print(myList.search(17)) print(myList.index(17)) myList.insert(2, 15) myList.printList() print() myList.remove(93) myList.remove(22) myList.printList()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started