什么时候用queue和stack?

Arrays和list是随机读取的,很灵活。

但如果你想用先进先出,或者先进后出的顺序。就可以用queue 和 stack。

 

Because they help manage your data in more a particular way than arrays and lists.

Queue is first in, first out (FIFO)

Stack is last in, first out (LIFO)

Arrays and lists are random access. They are very flexible and also easily corruptible. IF you want to manage your data as FIFO or LIFO it’s best to use those, already implemented, collections.

发表回复

您的电子邮箱地址不会被公开。