TutorMe homepage
Subjects
PRICING
COURSES
SIGN IN
Start Free Trial
Manish M.
PhD candidate at College of Information and Computer Science. UMass Amherst
Tutor Satisfaction Guarantee
Python Programming
TutorMe
Question:

Write a program that creates a queue using stacks and allows the user to perform enqueue and dequeue operations on it.

Manish M.
Answer:

1. Create a class Node with instance variables data and next. 2. Create a class Stack with instance variable items initialized to an empty list. 3. Define methods push, pop and is_empty inside the class Stack. 4. The method push appends data to items. 5. The method pop pops the first element in items. 6. The method is_empty returns True only if items is empty. 7. Create a class Queue with instance variables inbox and outbox, both initialized to an empty stack. 8. Define methods enqueue, dequeue and is_empty inside the class Queue. 9. The method enqueue pushes data to the stack inbox. 10. The method dequeue pops from the stack outbox if it is not empty. If it is empty, then all the elements from inbox are popped and pushed to outbox before popping from outbox. 11. The method is_empty returns True only if both the stacks inbox and outbox are empty. 12. Create an instance of Queue and present a menu to the user to perform operations on the queue. Here is the source code of a Python program to implement a queue using two stacks. The program output is shown below. class Queue: def __init__(self): self.inbox = Stack() self.outbox = Stack() def is_empty(self): return (self.inbox.is_empty() and self.outbox.is_empty()) def enqueue(self, data): self.inbox.push(data) def dequeue(self): if self.outbox.is_empty(): while not self.inbox.is_empty(): popped = self.inbox.pop() self.outbox.push(popped) return self.outbox.pop() class Stack: def __init__(self): self.items = [] def is_empty(self): return self.items == [] def push(self, data): self.items.append(data) def pop(self): return self.items.pop() a_queue = Queue() while True: print('enqueue <value>') print('dequeue') print('quit') do = input('What would you like to do? ').split() operation = do[0].strip().lower() if operation == 'enqueue': a_queue.enqueue(int(do[1])) elif operation == 'dequeue': if a_queue.is_empty(): print('Queue is empty.') else: dequeued = a_queue.dequeue() print('Dequeued element: ', int(dequeued)) elif operation == 'quit': break Program Explanation 1. An instance of Queue is created. 2. The user is presented with a menu to perform enqueue and dequeue operations on the queue. 3. The chosen operation is performed by calling the corresponding method.

GRE
TutorMe
Question:

How do I solve the reading comprehension exercises efficiently?

Manish M.
Answer:

Reading large passages to solve the comprehension exercises could be daunting specially when the clock is ticking. Here is a 3-step approach which can help you in solving reading comprehension exercises efficiently. 1. Read the questions to be answered before starting to read the passage 2. Skim the passage quickly to understand the context and the topic and try relating it to the questions you read based on the keywords which are common between questions and the paragraph text. Mark the paragraphs with the question number while skimming. 3. Read the passage from start to end and while reading the paragraph that is marked with a question number, select the appropriate answer for the question.

Software Engineering
TutorMe
Question:

What are the different types of software development models and which model is used when?

Manish M.
Answer:

The most popular software development models are the Waterfall model. Iterative model. Spiral model. V-shaped model. and Agile model. For example, in Waterfall model, all the software requirements are specified by the customer at the beginning which is then followed by designing the software modules to satisfy those requirements, implementing the software, testing the software, and finally deploying the software in production environment. In Agile model, the software is incrementally developed in iterations with the customer specifying the requirements to be included in each increment and the highest priority requirement is satisfied first so as to ensure a continuous delivery of valuable software. In practice, it is often the case that requirements are incomplete at the beginning and customers come up with new requests later during the software development, hence Waterfall model often fails in practice however, if a team is building a large software application for example, a bank website, or an e-commerce website then one needs to decide and freeze the major features that are facilitated by such applications because each major requirement, if added later during the development process can incur large amount of time and effort and can impact the profit. Thus, in practice, industries often use a hybrid approach for software development.

Send a message explaining your
needs and Manish will reply soon.
Contact Manish
Ready now? Request a lesson.
Start Session
FAQs
What is a lesson?
A lesson is virtual lesson space on our platform where you and a tutor can communicate. You'll have the option to communicate using video/audio as well as text chat. You can also upload documents, edit papers in real time and use our cutting-edge virtual whiteboard.
How do I begin a lesson?
If the tutor is currently online, you can click the "Start Session" button above. If they are offline, you can always send them a message to schedule a lesson.
Who are TutorMe tutors?
Many of our tutors are current college students or recent graduates of top-tier universities like MIT, Harvard and USC. TutorMe has thousands of top-quality tutors available to work with you.