private void addMemory(Block newOne)
 {
     Queue visitQ = new Queue();
     BTNode newTree = new BTNode(newOne);
     if (Free == null)
         Free = newTree;
     else
     {
         visitQ.Enqueue(Free);
         while (true)
         {
             BTNode curTree = (BTNode)visitQ.Dequeue();
             if (curTree.left() == null)
             {
                 curTree.setLeft(newTree);
                 return;
             }
             if (curTree.right() == null)
             {
                 curTree.setRight(newTree);
                 return;
             }
             visitQ.Enqueue(curTree.left());
             visitQ.Enqueue(curTree.right());
         }
     }
 }
 /* pre:  List of available memory blocks is empty.
  * post: Populates list with test data from text file. */
 // DO NOT MODIFY ANY METHODS BELOW
 public void readData(string FileName)
 {
     Console.WriteLine("List of available memory being populated ......");
     StreamReader Input = new StreamReader(FileName);
     while (!Input.EndOfStream)
     {
         Block newOne = new Block(int.Parse(Input.ReadLine()), int.Parse(Input.ReadLine()), bool.Parse(Input.ReadLine()));
         addMemory(newOne);
     }
     Console.WriteLine("List of available memory populated");
     Console.WriteLine();
 }
 public int CompareTo(Block Mem)
 {
     return this.MemID - Mem.MemID;
 }
        private Block getSmallestBlock(BTNode T,int Size, Block min)
        {
            if (T == null)
                return new Block(-1,9999999,false);

            Block minLeft = getSmallestBlock(T.left(), Size, min);
            Block minRight = getSmallestBlock(T.right(), Size, min);

            if ((minLeft.Size < minRight.Size)&&(minLeft.Size > Size))
                min = minLeft;
            else if (minRight.Size > Size)
                min = minRight;

            Block curBlock = (Block)T.value();

            if ((curBlock.Size > Size)&&(min.Size > curBlock.Size))
                min = curBlock;

            return min;
        }
 private Block recursiveFindMemory(BTNode T, int Size, Block CurMin)
 {
     if (T != null)
     {
         if (((Block)T.value()).Size < CurMin.Size)
         {
             Block temp = (Block)T.value();
             recursiveFindMemory(T.left(), Size, temp);
             recursiveFindMemory(T.right(), Size, temp);
         }
         else
         {
             recursiveFindMemory(T.left(), Size, CurMin);
             recursiveFindMemory(T.right(), Size, CurMin);
         }
     }
     return CurMin;
 }