Question: How to implement a queue using one integer. this should store value 0 to 9. example suppose queue has first value 2 then insert 4 then 6 so it should look like 246. first value should be popped as 2. then it should be 46. program should support 0 in all the levels also. example queue should handle like 01235 also, 0 as first value in queue. remember 0 just to use integer, nothing else as data storage.

Solution: Many solutions are possible. One possible solution is given below
Steps:-
1. represent each number with 4 bits as the max no. needs 4 bits.
2. take the first no. say 4. (bit representation 0100) lets put this in a variable called queueInteger.
3. another variable (say queuePointer)to take the element from queue.The value in it will be 15(which is 1111).
4. if you want to print the first number just do and (&) operation between queueInteger and queuePointer.(which is 0100 & 1111 gives 0100 which is 4).
5. Or if you want to add more elements to queue then left shift the queueInteger by 4 positions and do the or(||) operation with the new number(say 5 so queueInteger becomes 0100 0000 || 0101 gives 0100 0101).
6. Then left shift the queuePointer by 4 bits.(now it will become 1111 0000)
7. If you want to print the element then do queueInteger & queuePointer you will get4.
8. If you want to delete it you can right shift the queuePointer variable by 4 bits.