/*
Name - Jayneel Shah
Date - 23/10/21
Topic - Application of classes in Java
Program to implement growable self sorting array(GSSArray)
*/
import java.util.*;
class GSSArray
{
private int [] arr;
private int size;
private int lastIndex = -1;
//default constructor
GSSArray(int n)
{
arr = new int[n];
size = n;
}
int i = 0;
//insert function
public void insert(int value)
{
//if size is less than defined size regular addition
if (size > i)
{
lastIndex++;
arr[lastIndex] = value;
i++;
display();
}
//if the size is more then it first increases the size and then performs addition in the array
else
{
increaseSize();
lastIndex++;
arr[lastIndex] = value;
i++;
display();
}
}
//incrase size function - it doubles the size and copie the elements of old array in the new array
private void increaseSize()
{
int[] arr1 = new int[arr.length*2];
for(int i=0;i