Saturday, August 06, 2011

Organizing clothes using Data Structure

Due to lack of hanger space in my present wardrobe, I have to keep my clothes folded. I usually pick up something from the top of the pile for wearing. Which means I keep wearing the a small subset of my clothes repeatedly. Ideally I would have liked to wear all the clothes. But its too much trouble to take a tshirt out from middle of a pile; the entire pile gets disheveled.

The solution is actually quite simple. Think of the tshirt pile as a stack. What I want is basically a queue. So all that is left to do is to somehow "implement a queue using a stack". The CS grads have already faced this problem in their Algorithm and Data Structure courses. I applied the same technique.

I used two stacks, one for putting the washed clothes in (enqueue) and another for taking out the clothes for wearing (dequeue). If the pile for wearing is empty, [and here comes the important step] then turn the washed clothes pile upside down and keep it in place for the wearing pile.

Its good to know that Data Structure knowledge is useful beyond computers too !!