Implement a generic (Generics) data structure "queue" that allows you to store objects (reference variables). Do not use the standard .NET collection classes, only use arrays as an internal structure for storing data.

I do not fully understand what is required of me. Explain to the oak tree. Thank you in advance.

Reported as a duplicate by participants in zRrr , Kromster , cheops , VenZell , user194374 Jun 10 '16 at 9:40 .

This question has been marked as a duplicate of an existing one.

  • you need to make a generic class Queue, inside which data is stored in arrays - Grundy
  • We need to create a generic (Generics) class that would have this functionality: wiki: the queue Implementing data storage inside a class through an array. - Alex Krass

1 answer 1

̶Z̶i̶m̶a̶ Session is close. The generalized (Generics) data structure “queue” means that this queue can store different types of data, that is, there can be a queue of ints, strings or generally a queue of queues. This is achieved by Generics methods.

The first answer from Google to your question:

class SimpleQueue<T> where T : class { private const int _capasityIncrease = 5; private T[] _array; private int _count; private int _head; private int _tail; public int Count { get { return _count; } } public SimpleQueue() { _array = new T[5]; _count = 0; _head = 0; _tail = 0; } public void Enqueue(T item) { if (_tail >= _array.Length) { Array.Resize(ref _array, _array.Length + _capasityIncrease); } _array[_tail] = item; _count++; _tail++; } public T Dequeue() { if (_count == 0) { throw new InvalidOperationException("Очередь пуста"); } T item = _array[_head]; _array[_head] = null; _head++; _count--; return item; } }