Question

Data Structures and Algorithm (Stacks and Queues)

Imagine you have a Queue of integers, Q1 and Q2. Draw a picture of Q1 and Q2 after the following operations:

**Note: make sure that ALL variables are simulated.**

Data are: 5,7,12,4,0,4,6 (these are the numbers) Algorithm: 1 loop (not end of the file) 1read number 2enqueue(Q1,number) 3en

0 0
Add a comment Improve this question Transcribed image text
Answer #1

The processing of the Queue Q1 and Q2 is given below :

Step 1 :

Q1 5
Q2 5
Q1
Q2 5 5

Step 2 :

Q1 7
Q2 7 5 5
Q1
Q2 7 7 5 5

Step 3 :

Q1 12
Q2 12 7 5 5
Q1
Q2 12 12 7 7 5 5

Step 4 :

Q1 4
Q2 4 12 7 7 5 5
Q1
Q2 4 4 12 12 7 7 5 5

Step 5 :

Q1 0
Q2 0 4 4 12 12 7 7 5 5
Q1
Q2 0 0 4 4 12 12 7 7 5 5

Step 6 :

Q1 4
Q2 4 0 0 4 4 12 12 7 7 5 5
Q1
Q2 4 4 0 0 4 4 12 12 7 7 5 5

Step 7 :

Q1 6
Q2 6 4 4 0 0 4 4 12 12 7 7 5 5
Q1
Q2 6 6 4 4 0 0 4 4 12 12 7 7 5 5
Add a comment
Know the answer?
Add Answer to:
Data Structures and Algorithm (Stacks and Queues) Imagine you have a Queue of integers, Q1 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Imagine that the contents of queue Q1 and queue Q2 are as shown. What would be...

    Imagine that the contents of queue Q1 and queue Q2 are as shown. What would be the contents of Q3 after the following code is executed? The queue contents are shown front (left) to rear (right). Q1: 42 30 41 31 19 20 25 14 10 11 12 15 Q2: 4 5 4 10 13 1 Q3 = createQueue 2 count = 0 3 loop (not empty Q1 and not empty Q2)      1 count = count + 1     ...

  • 3) Stacks vs Queues: a) A Circular Array is a common data structure for a buffer...

    3) Stacks vs Queues: a) A Circular Array is a common data structure for a buffer (a type of queue). Why is this advantageous over a regular array? (Hint: think about common queue operations and what they do to an array). b) Show a traversal of the following tree using a stack: 26 1 25 2 17 3 2. (19 7 1 (The numbers under the bubbles are a node number, not the data. ) c) Why would using a...

  • Computer Science-Data Structures and Algorithms

    What would be the contents of queue Q1 and Q2 after the following code is executed and the following data are entered?1 Q1 = createQueue2 Q2 = createQueue3 loop (not end of file)1 read number2 enqueue (Q1,number)3 enqueue (Q2,number)4 loop (not empty Q1)1 dequeue (Q1,x)2 enqueue (Q2,x)5 end loop4 end loopThe data are 5, 7, 12, 4, 0, 4, 6

  • Module 4 follow the materials available at Topic - Stacks and Queues. You should have a...

    Module 4 follow the materials available at Topic - Stacks and Queues. You should have a good understanding of Lists at  Topic - Basic Data structures as a Queue and a Stack are simply implementation of a List with specific properties. Assignment - Implement a Stack computer in Javascript (you will turn in a link to your program in JSFiddle). This is a simple computer that keeps a stack, when a number is entered it goes onto the top of the...

  • You are going to create a Queue. (alternately you can create a list and simply implement...

    You are going to create a Queue. (alternately you can create a list and simply implement enqueue and dequeue functions in the List – that will technically make it a queue). You will fill the first list with numbers consecutively numbered from 2 to n where n is entered by the user (we will call this Q1). When creating your Queue object use the correct function names for enqueue and dequeue functions. Again – sorry, cannot use an Javascript array...

  • IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us...

    IN PYTHON 3: In this version of Radix Sort we use Queues very naturally. Let us consider the following set of positive integers: 311, 96, 495, 137, 158, 84, 145, 63 We will sort these numbers with three passes. The number of passes is dependent on the number of digits of the largest number - in this case it is 495. In the first pass we will go through and sort the numbers according to the digits in the units...

  • help finish Queue, don't think I have the right thing. # 1. After studying the Stack...

    help finish Queue, don't think I have the right thing. # 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...

  • Description In this homework, you are asked to implement a multithreaded program that will allow ...

    Description In this homework, you are asked to implement a multithreaded program that will allow us to measure the performance (i.e, CPU utilization, Throughput, Turnaround time, and Waiting time in Ready Queue) of the four basic CPU scheduling algorithms (namely, FIFO, SJE PR, and RR). Your program will be emulating/simulating the processes whose priority, sequence of CPU burst time(ms) and I'O burst time(ms) will be given in an input file. Assume that all scheduling algorithms except RR will be non-preemptive,...

  • Using C++, data structures, C++ STL, inputs and expected outputs are shown below. Max Heap Heap...

    Using C++, data structures, C++ STL, inputs and expected outputs are shown below. Max Heap Heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either > (in a max heap) or s (in a min heap) the key of C. The node at the "top" of the heap (with no parents) is called the root node. In binary-tree based heap, it...

  • A priority queue is a collection of items each having a priority. A priority queue supports three...

    A priority queue is a collection of items each having a priority. A priority queue supports three fundamental operations. You can ask a priority queue whether it is empty. You can insert an item into the priority queue with a given priority. You can remove the item from the priority queue that has the smallest priority. For example, suppose that you start with an empty priority queue and imagine performing the following steps. Insert item "one" with priority 10. Insert...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT