You are on page 1of 2

North South University

CSE 225L: Data Structure Lab


Summer 2020, Lab Midterm Exam, Full Marks: 100, Time: 1.00 hour.
Name: Id: Section: 4

1. Print palindrome number (50)


Back then, I was new in Computer science. I had just learned how to check palindrome
number. Then my friend came to me and talking about a similar problem. He was telling
me to create a palindrome number. I was excited and trying to put a logic. But then he
gave me a limitation. He asked me to solve that problem by using any of his 2 given
structures and must have to solve using only one loop.
a. Stack
b. Queue

Then I got confused. Although he was telling me that it’s a very easy program, I couldn’t
find the right solution using these structures. I think you can help me now as you’ve said,
you know all these structures. My friend told me that one of these structures is very
helpful to solve this type of problem.

Input: 5 Input: 3 Input: 9

Output: 1234554321 Output: 123321 Output: 123456789987654321

2. Reversing the first K elements of a Queue (50)


Given an integer k and a queue of chars, you need to reverse the order of the first k
elements of the queue, leaving the other elements in the same relative order. For this
purpose, add a public function called “Reverse(K)” upon calling which the first k
elements of the queue will be reversed. For e.g. if a queue contains (from front to rear):
‘a’, ‘c’, ‘d’, ‘b’, ‘e’, and reverse(3) is called upon this queue then after the execution of
this reverse function call, the queue will contain: ‘d’, ‘c’, ‘a’, ‘b’, ‘e’.

You might also like