示例#1
0
 public bool AddAll(int index, IntBag other)
 {
     // throws NullPointerException if other == null,
     // ArrayIndexOutOfBoundsException if index < 0,
     // and IndexOutOfBoundsException if index > numObjs
     if (index > NumObjs)
     {
         ThrowIndexOutOfBoundsException(index);
     }
     if (other.NumObjs <= 0)
     {
         return(false);
     }
     // make IntBag big enough
     if (NumObjs + other.NumObjs > Objs.Length)
     {
         Resize(NumObjs + other.NumObjs);
     }
     if (index != NumObjs) // make room
     {
         Array.Copy(Objs, index, Objs, index + other.NumObjs, other.NumObjs);
     }
     Array.Copy(other.Objs, 0, Objs, index, other.NumObjs);
     NumObjs += other.NumObjs;
     return(true);
 }
示例#2
0
 /** Adds the ints from the other IntBag without copying them.  The size of the
  *  new IntBag is the minimum necessary size to hold the ints. */
 public IntBag(IntBag other)
 {
     if (other == null)
     {
         NumObjs = 0;
         Objs    = new int[1];
     }
     NumObjs = other.NumObjs;
     Objs    = new int[NumObjs];
     Array.Copy(other.Objs, 0, Objs, 0, NumObjs);
 }
示例#3
0
 public bool AddAll(IntBag other)
 {
     return(AddAll(NumObjs, other));
 }