Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

You are given a Stack of people. They should be paired off as man with woman, woman with man. If a male and a female

You are given a Stack of people. They should be paired off as man with woman, woman with
man. If a male and a female are consecutive in the stack, they get paired immediately. If there
are consecutive females found without any subsequent males, then the spare females should
be saved in a Queue for future pairing. If there are consecutive males found without any
subsequent females, we try to pair a male with the first spare female [if available] from the
Queue. If no spare female is available, then the male is discarded. The same logic applies to
consecutive females without any subsequent males.
The stack class and the Queue class are implemented for you. The public instance
methods in the Stack class are push(), pop(), peek(), and isEmpty(). The public
instance methods in the Queue class are enq(), deq(), peek(), and isEmpty(). In
both classes, isEmpty() returns a boolean value, peek() and pop() returns None for
underflow. All other members of both classes are private. You can only use the public
instance methods. No need to consider the overflow exception for both Stack and Queue
classes.
Your task is to complete the given method dance_pair() that takes a stack and prints
every male-female pair.
Every male and female are written in this way - M_id or F_id. A method called
id_gender_extractor(s) is implemented for you that returns the id and gender from a
string, s .
You cannot use any data structure other than stack and queue. please follow the picture of the question
Given:
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions

Question

Convert ( 1 1 0 1 1 0 1 0 1 0 0 ) 2 to base 1 6

Answered: 1 week ago