@@ -16,7 +16,7 @@ public class Queue<T> : IEnumerable<T> where T : IComparable<T>
16
16
private int _tailPointer { get ; set ; }
17
17
18
18
// The internal collection.
19
- private object [ ] _collection { get ; set ; }
19
+ private T [ ] _collection { get ; set ; }
20
20
private const int _defaultCapacity = 8 ;
21
21
22
22
// This sets the default maximum array length to refer to MAXIMUM_ARRAY_LENGTH_x64
@@ -45,7 +45,7 @@ public Queue(int initialCapacity)
45
45
_size = 0 ;
46
46
_headPointer = 0 ;
47
47
_tailPointer = 0 ;
48
- _collection = new object [ initialCapacity ] ;
48
+ _collection = new T [ initialCapacity ] ;
49
49
}
50
50
51
51
@@ -77,7 +77,7 @@ private void _resize(int newSize)
77
77
{
78
78
//Array.Resize (ref _collection, newSize);
79
79
80
- var tempCollection = new object [ newSize ] ;
80
+ var tempCollection = new T [ newSize ] ;
81
81
Array . Copy ( _collection , _headPointer , tempCollection , 0 , _size ) ;
82
82
_collection = tempCollection ;
83
83
}
@@ -123,7 +123,7 @@ public T Top
123
123
if ( IsEmpty )
124
124
throw new Exception ( "Queue is empty." ) ;
125
125
126
- return ( T ) _collection [ _headPointer ] ;
126
+ return _collection [ _headPointer ] ;
127
127
}
128
128
}
129
129
@@ -166,7 +166,7 @@ public T Dequeue()
166
166
throw new Exception ( "Queue is empty." ) ;
167
167
168
168
var topItem = _collection [ _headPointer ] ;
169
- _collection [ _headPointer ] = null ;
169
+ _collection [ _headPointer ] = default ( T ) ;
170
170
171
171
// Decrement the size
172
172
_size -- ;
@@ -193,7 +193,7 @@ public T Dequeue()
193
193
_tailPointer = Array . IndexOf ( _collection , tail ) ;
194
194
}
195
195
196
- return ( T ) topItem ;
196
+ return topItem ;
197
197
}
198
198
199
199
/// <summary>
@@ -207,7 +207,7 @@ public T[] ToArray()
207
207
int j = 0 ;
208
208
for ( int i = 0 ; i < _size ; ++ i )
209
209
{
210
- array [ j ] = ( T ) _collection [ _headPointer + i ] ;
210
+ array [ j ] = _collection [ _headPointer + i ] ;
211
211
j ++ ;
212
212
}
213
213
0 commit comments