Final answer:
In response to the question, we define a Person class and a Queue class with methods for sorting based on last name or age using quicksort.
The Queue class contains a set of Person instances and provides functionality to sort the queue in descending order by the specified attribute.
Step-by-step explanation:
To create a program that fulfills the requirements, we would define a Person class with attributes for first name, last name, and age. We would also define a Queue class to manage a collection of Person instances. Below is an example implementation with methods to sort by last name and age using quicksort.
First, we declare the Person class:
class Person:
def __init__(self, first_name, last_name, age):
self.first_name = first_name
self.last_name = last_name
self.age = age
Next, we define the Queue class:
class Queue:
def __init__(self):
self.people = []
def enqueue(self, person):
self.people.append(person)
def sort_by_last_name_desc(self):
self.people = self.quicksort(self.people, key=lambda x: x.last_name, reverse=True)
def sort_by_age_desc(self):
self.people = self.quicksort(self.people, key=lambda x: x.age, reverse=True)
# The quicksort method would be defined here
The program would prompt the user to add five people to the queue, display the contents, and sort it in descending order by last name and age.