美文网首页
Data Structure(9.17)

Data Structure(9.17)

作者: 文方方 | 来源:发表于2017-09-17 14:12 被阅读0次

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.

相关文章

网友评论

      本文标题:Data Structure(9.17)

      本文链接:https://www.haomeiwen.com/subject/ztgpsxtx.html