Inserts a key in arr [ ] of given capacity . n is current size of arr [ ] . This function returns n + 1 if insertion is successful , else n .
public static int insertSorted ( int [ ] arr , int n , int key , int capacity ) {