Ch3-3: popat(int idx) of setofstack

来源:互联网 发布:电影自动采集源码 编辑:程序博客网 时间:2024/05/10 16:26

Continue to use class to design solution, also, start to use STL, such as container (vector, stack, set, ...). save time and to be more professional.

The design without popat method is similar to the one to devide a single array into 3 stacks. 

But the class of setofstack with popat should be more carefully.


for example: 

bool empty(){  // empty of the whole set//if(cur==0) return st[cur].empty();            // this is not working because it might have             // blank substack in the middle of full stack            // so need to have while condition to find the last             // not-empty stack        // if (cur!=-1 && st[cur].empty()) --cur; --->            // this one only find the previous stack of             // empty stack, need to use while condition insteadwhile(cur!=-1 && st[cur].empty()) --cur;if (cur==-1) return true;return false;}



Full code.  Still, this is modified from Hawstein's code but may not the best solution, learn from others too..


output:

Executing the program....$demo 19181716151413121110huxiaolin ...TOT


0 0
原创粉丝点击