File tree Expand file tree Collapse file tree
DataStructures/BinarySearchTree Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -316,7 +316,12 @@ private IList<TKey> GetKeysInOrder(BinarySearchTreeNode<TKey>? node)
316316 return [ ] ;
317317 }
318318
319- return [ ..GetKeysInOrder ( node . Left ) , node . Key , ..GetKeysInOrder ( node . Right ) ] ;
319+ // Use mutable list approach instead of spread operator for better performance
320+ var result = new List < TKey > ( ) ;
321+ result . AddRange ( GetKeysInOrder ( node . Left ) ) ;
322+ result . Add ( node . Key ) ;
323+ result . AddRange ( GetKeysInOrder ( node . Right ) ) ;
324+ return result ;
320325 }
321326
322327 /// <summary>
@@ -331,7 +336,14 @@ private IList<TKey> GetKeysPreOrder(BinarySearchTreeNode<TKey>? node)
331336 return [ ] ;
332337 }
333338
334- return [ node . Key , ..GetKeysPreOrder ( node . Left ) , ..GetKeysPreOrder ( node . Right ) ] ;
339+ // Use mutable list approach instead of spread operator for better performance
340+ var result = new List < TKey >
341+ {
342+ node . Key ,
343+ } ;
344+ result . AddRange ( GetKeysPreOrder ( node . Left ) ) ;
345+ result . AddRange ( GetKeysPreOrder ( node . Right ) ) ;
346+ return result ;
335347 }
336348
337349 /// <summary>
@@ -346,7 +358,12 @@ private IList<TKey> GetKeysPostOrder(BinarySearchTreeNode<TKey>? node)
346358 return [ ] ;
347359 }
348360
349- return [ ..GetKeysPostOrder ( node . Left ) , ..GetKeysPostOrder ( node . Right ) , node . Key ] ;
361+ // Use mutable list approach instead of spread operator for better performance
362+ var result = new List < TKey > ( ) ;
363+ result . AddRange ( GetKeysPostOrder ( node . Left ) ) ;
364+ result . AddRange ( GetKeysPostOrder ( node . Right ) ) ;
365+ result . Add ( node . Key ) ;
366+ return result ;
350367 }
351368
352369 /// <summary>
You can’t perform that action at this time.
0 commit comments