0% found this document useful (0 votes)
23 views2 pages

Pseudocode Algorithms for Queues and Stacks

This document contains 10 questions about data structures and algorithms related to stacks, queues, and their implementations: 1. Write pseudo code and C code to implement a stack using queue(s) and explain how it works. 2. Describe the operations of pushing and popping elements onto a stack implemented with queues. 3. Write pseudo code to reverse the order of elements in a queue, using a stack as an intermediate container.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views2 pages

Pseudocode Algorithms for Queues and Stacks

This document contains 10 questions about data structures and algorithms related to stacks, queues, and their implementations: 1. Write pseudo code and C code to implement a stack using queue(s) and explain how it works. 2. Describe the operations of pushing and popping elements onto a stack implemented with queues. 3. Write pseudo code to reverse the order of elements in a queue, using a stack as an intermediate container.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

SCS 1201

Data Structures and Algorithms

Tutorial 03

1. Write a pseudo code algorithm to Implement a Stack using Queue(s)


• Describe how the pseudo code algorithm works. You may use suitable diagram(s)
to answer the question
• Convert the above pseudo-code into c code.
• Prove the validity of your program using test data and test results

2. Describe how the following set of operations work on the code written by you above. You
may use a suitable diagram to illustrate the answer.

1. Push(‘a’)
2. Push(‘b’)
3. Push(‘c’)
4. Pop
5. Push(‘d’)
6. Pop
7. Pop
8. Pop
9. Push(‘e’)

3. Write a pseudo code algorithm to reverse a set of numbers stored in a queue(s).


Note: You may use a stack as an intermediate container.

• Convert the above pseudo code algorithm into a C program


• Using the above C program written by you, generate the following outputs using
the given inputs.

Input: Q = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
Output: Q = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10]
Input: [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
4. Given an efficient circular array-based queue (Q) capable of holding 10 objects. Show the

final contents of the Q after the following code segment is executed:


Int k
for (k = 1; k ≤ 7; k++)
{
[Link](k);
}
for ( k = 1; k ≤ 7; k++)
{
[Link]([Link]());
}

5. Consider the following Pseudo Algorithm.

Begin
Initialize Stacks S1 and S2
Push all inputs into Stack S1

Procedure P () {
While (! [Link] ())
Push S2 (Pop S1 ())
}
While (! [Link] ())
Print (pop S2 ())
End

a. What is the pseudo code above intended to do?


b. If the following values were inserted into the above pseudo code, what would be
the final output? Values are: 34, 12,18,23,55,11,9

6. Write a pseudo code algorithm and c program to generate binary numbers between 0 to
n using a queue

7. Write an algorithm to insert an element into a queue?

8. What are the two problems associated with the linear queue?
9. Write an algorithm to delete an element from a circular queue.

10. Write a pseudo code algorithm to Implement a Queue using two Stacks.

You might also like