0% found this document useful (0 votes)
10 views1 page

UCS301 Lab: Queue Operations and Programs

The document outlines a lab assignment for UCS301 Data Structures focusing on queue operations, including both simple and circular queues. It includes tasks such as interleaving queue halves, finding non-repeating characters, and implementing a stack using queues. Additionally, it presents challenges related to generating binary numbers, sorting a queue without extra space, and managing student preferences for sandwiches in a queue system.

Uploaded by

Diicker123
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)
10 views1 page

UCS301 Lab: Queue Operations and Programs

The document outlines a lab assignment for UCS301 Data Structures focusing on queue operations, including both simple and circular queues. It includes tasks such as interleaving queue halves, finding non-repeating characters, and implementing a stack using queues. Additionally, it presents challenges related to generating binary numbers, sorting a queue without extra space, and managing student preferences for sandwiches in a queue system.

Uploaded by

Diicker123
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

UCS301 Data Structures

​ Lab Assignment 4: Queues​


(Week 4)

1)​ Develop a menu driven program demonstrating the following operations on simple
Queues: enqueue(), dequeue(), isEmpty(), isFull(), display(), and peek().

2)​ Develop a menu driven program demonstrating the following operations on Circular Queues:
enqueue(), dequeue(), isEmpty(), isFull(), display(), and peek().

3)​ Write a program interleave the first half of the queue with second half.
Sample I/P: 4 7 11 20 5 9 Sample O/P: 4 20 7 5 11 9

4)​ Write a program to find first non-repeating character in a string using Queue. Sample I/P: a a
b c Sample O/P: a -1 b b

5)​ Write a program to implement a stack using (a) Two queues and (b) One Queue.

Additional Questions
1)​ Given a function n, write a function that generates and prints all binary numbers with decimal
values from 1 to n.
Input: n = 2​
Output: 1, 10
[Link]

2) Given a queue with random elements, we need to sort it. We are not allowed to use extra space. The
operations allowed on queue are: ​
1. ​ enqueue() : Adds an item to rear of queue.
2.​ dequeue() : Removes an item from front of queue.
3.​ isEmpty() : Checks if a queue is empty.
Input: 11, 5, 4, 21
Output: 4, 5, 11, 21
​ [Link]

3) Given a Queue consisting of first n natural numbers (in random order). The task is to check whether
the given Queue elements can be arranged in increasing order in another Queue using a stack. The
operation allowed are:
1.​ Push and pop elements from the stack
2.​ Pop (Or Dequeue) from the given Queue.
3.​ Push (Or Enqueue) in the another Queue.
Input : Queue[] = { 5, 1, 2, 3, 4 } ​
Output : Yes
Check if a queue can be sorted into another queue using a stack - GeeksforGeeks

4) The school cafeteria offers circular and square sandwiches at lunch break, referred to by
numbers 0 and 1 respectively. All students stand in a queue. Each student either prefers square or
circular sandwiches. The number of sandwiches in the cafeteria is equal to the number of students. The
sandwiches are placed in a stack. At each step:
●​ If the student at the front of the queue prefers the sandwich on the top of the stack, they
will take it and leave the queue.
●​ Otherwise, they will leave it and go to the queue's end.
This continues until none of the queue students want to take the top sandwich and are thus
unable to eat
Input: students = [1,1,0,0], sandwiches = [0,1,0,1]
Output: 0
Number of Students Unable to Eat Lunch - LeetCode

You might also like