/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, OCaml, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
class VectorTest{
public static void main(String[] args){
System.out.println("Prueba de la clase Vector");
int v1[] = {1, 3, 4, 4, 6};
int v2[];
int i;
for(int n=0; n<8; n++){
System.out.print("v1: ");
for(i=0; i<v1.length-1; i++) System.out.print(v1[i] + ", ");
System.out.println(v1[i] + "\nn : " + n);
v2 = Vector.insertar(v1, n);
System.out.print("v2: ");
for(i=0; i<v2.length-1; i++) System.out.print(v2[i] + ", ");
System.out.println(v2[i]);
System.out.println("-----------------------");
}
}
}
class Vector{
static int[] insertar(int[] v1, int n){
int[] v2 = new int[v1.length+1];
int i=0, j=0;
while(i<v1.length && v1[i] <= n){
v2[j++] = v1[i++];
}
v2[j++] = n;
while(i<v1.length){
v2[j++] = v1[i++];
}
return v2;
}
}