Is a Queue faster than a List if the List is used in FIFO format?
Or the difference is only in the lines of code ...
PS Code example:
Case A:
var list = new List<int>() {1,2,3,4,5,6,7,8,9}; for (int i = 0; i < list.Count; i++) { // работа с list[i] if (BOOL) //BOOL в 90% случаев = true { list.RemoveAt(i--); } } Case B:
var queue = new Queue<int>(); queue.Enqueue(1); queue.Enqueue(2); queue.Enqueue(3); queue.Enqueue(4); queue.Enqueue(5); queue.Enqueue(6); queue.Enqueue(7); queue.Enqueue(8); queue.Enqueue(9); for (int i = 0; i < queue.Count; i++) { var integer = queue.Dequeue(); // работа с integer if (!BOOL) //BOOL в 90% случаев = true (Инвертировано) { queue.Enqueue(integer); } } Case C:
var list = new List<int>() {1,2,3,4,5,6,7,8,9}; for (int i = 0; i < list.Count; i++) { // работа с list[i] if (BOOL) //BOOL в 90% случаев = true { //Обработать как то иначе текущий list[i]... } } PPS The case of "Process as otherwise" and the Queue did not describe
List<T>on the principle of FIFO? "Out of the box" he does not have such functionality. With a great desire, this can be emulated, but the meaning of such witches is not very clear - DreamChild