Data Structure(9.17)

1.To solve the number counter question

Image there are n persons stand in a line, from the left to the right the number is from 1 to n, and now from left to right say the number like this "1,2,1,2,1,2........", those whoes number is 1 stand out, those whose number is 2 stand to the right of the line. Do this until all the people sthands out. Please output the order of theirs stands-out.

2.other's idea

Store the numbers with a queue and ergodic the queue output the first one
, and the second one push to the tail of the queue until the queue is empty.

3.my code


4.summary:

This sample question can indicate an truth that my ability of code writting is poor just like my poor English. There's a big apsce for me to make process. Right?

Ok, let's analysis the question, when meet a queue problem, queue is a good way to get the solution. It makes full use of the character of the queue first in first out and the output order is  in order.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容