Insert into a Generic Box (Id-1492)

Just for Practice 6 Additional [26-Feb-2018 to 3-Mar-2018]

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1492

A generic box has three entry points:

First – Points to the first element in the box

Last – Points to the last element in the box

Mid – Points to the middle element in the box (calculated as (first+last)/2)

Insertion and deletion can be done through all the three points. Initially all the three entry points are -1. All the three entry points are updated for the first element that is inserted into the box. And for other insertions last and mid are updated. For each delete operation, update mid and last entry points. All entry points must become -1 when the box becomes empty. Provide a function to check if the box is full and also a function to check if the box is empty. Define a function print for the generic box. If the box is empty then it must print “Box empty”, print all elements from first position to last otherwise.

Input Format:

Choice for type of element (1 for int and 2 for string data)

Choice for operation in generic box

(1- check empty, 2 – is full, 3 – Insert through first entry point, 4 – Insert through last entry point, 5 – Insert through mid entry point

6 – Delete through first entry point, 7 – Delete through last entry point, 8 – Delete through mid entry point, 9 -Print, 10 – Exit

For insert options 3, 4 and 5

Element to be inserted

Output Format:

For options 1 and 2 print ‘Empty’ or ‘Not empty’, ‘Full’ or ‘Not full’ appropriately

Print elements in the box when print is given

Hint: Implement your isfull and isempty as given in the problem description


Please Comment Working if the code worked to you

If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂

Example: <pre> Your Code </pre>


C++ Code

C++ Code 


The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.


Click Here to Leave a Comment Below 18 comments
Mufaddal Lokhandwala - March 22, 2018

this code is not working
Segmentation fault (core dumped) occurs


qwerdsaq - March 24, 2018

code is not working please correct it

cupcake911 - March 26, 2018

please correct it the code isn’t working… 😦

Mufaddal Lokhandwala - March 26, 2018

still not working

123124 - March 26, 2018

Code is not working!!

yoyoy - March 27, 2018

code isnt working

hutch - March 30, 2018

check this code once more
it’s showing segmentation fault

kkr - April 5, 2018

second code is working

maddy - April 5, 2018

the second code is still not working for me…is there anything to be changed?

rahul - March 27, 2019

extremly fine working bro

Harshit - March 29, 2019

thanks bro, its working fine

priyojit - March 30, 2019

The second code is not running for me too bro

vgh - April 7, 2019

any one pseudo code please


Leave a Reply: