Advertisement
Pearlfromsu

fdaf

Feb 14th, 2024
1,246
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ClassLibrary1
  8. {
  9.     public class OwnQueue<T>
  10.     {
  11.         private T[] mass;
  12.         int _count = 0, _capacity = 4;
  13.         int _head = 0, _tail = 0;
  14.         public int Count
  15.         {
  16.             get
  17.             {
  18.                 return _count;
  19.             }
  20.             set
  21.             {
  22.                 if (value > _capacity)
  23.                 {
  24.                     while(_capacity < value)
  25.                         _capacity *= 2;
  26.                     T[] newArr = new T[_capacity];
  27.                     int j = 0;
  28.                     if (_head <= _tail)
  29.                         for (int i = _head; i <= _tail; i++)
  30.                             newArr[j++] = mass[i];
  31.                     if (_head > _tail)
  32.                     {
  33.                         for (int i = _head; i < _capacity; i++)
  34.                             newArr[j++] = mass[i];
  35.                         for (int i = 0; i <= _tail; i++)
  36.                             newArr[j++] = mass[i];
  37.                     }
  38.                     mass = newArr;
  39.                     _head = 0;
  40.                     _tail = _count - 1;
  41.                 }
  42.                 _count = value;
  43.             }
  44.         }
  45.         public void Enqueue(T elem)
  46.         {
  47.             this.Count++;
  48.             if(_head + 1 >= _capacity)
  49.             {
  50.                
  51.             }
  52.         }
  53.        
  54.         public OwnQueue()
  55.         {
  56.             this._count = 0;
  57.             this._capacity = 4;
  58.            
  59.         }
  60.     }
  61. }
  62.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement