Thursday, 7 February 2013

Insertion



public class ArrayList {

int [] arr;
int arrSize;
int currentIndex;


public void MyArrayList(int size) {
arr=new int[size];
arrSize=size;
currentIndex=-1;

}

public void insert (int value){
   if (currentIndex >= arr.length-1){
  int [] Temp =new int [arrSize*2];
  for (int i = 0; i<arr.length ; i++)
  {
  Temp[i] = arr[i];
  }
  currentIndex ++;
  arr = Temp;
  arr[currentIndex] = value;
 
 
   }
         
}

No comments:

Post a Comment