Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# Please continue code in def quick_sort_array() and def quick_sort_linked_list() Quick_sort in python ( 1. Simple list, 2.Linked list,) # Code item_list = [a, c,
# Please continue code in def quick_sort_array() and def quick_sort_linked_list()
Quick_sort in python ( 1. Simple list, 2.Linked list,)
# Code
item_list = ["a", "c", "m", "b", "r", "e", "t"]
print("------ Simple array ------") sa = SimpleArrayClass() #insert operation for i in range(len(item_list)): sa.insert_item(item_list[i]) print("Current list:\t", end = " ") sa.print_items() #sort operation sa.quick_sort_array()
class SimpleArrayClass: def __init__(self): self.item_list = [] def insert_item(self, data): self.item_list.insert(0, data) def print_items(self): print(self.item_list) def quick_sort_array(self): """Sort the array by using quicksort."""
###################################
print("------ Linked list ------") ll = LinkedListClass()
#insert operation for i in range(len(item_list)): ll.insert_item(item_list[i]) print("Current list:\t", end = " ") ll.print_items() #sort operation ll.quick_sort_linked_list() ll.print_items()
class LinkedListShoppingListManagerClass: class Node: def __init__(self, data): self.data = data self.next = None def __init__(self): self.head = None self.size = 0 def insert_item(self, item): new_node = self.Node(item) new_node.next = self.head self.head = new_node self.size += 1 def print_items(self): cur = self.head arr = [] while cur: arr.append(str(cur.data)) cur = cur.next print(arr, end=" ") def quick_sort_linked_list(self): """ """
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