I want to insert an element into the right place that order maintains in the sorted list. I allocated 2*n size for the array and filled the rest with 999 since they are not used currently.
ordered_insert(int number,int array[],int size){
int i=0;
int temp1,temp2,index;
while(eleman>array[i]){
i++;}
//push the rest to right by one
index=i;
if(i<size){
temp1=array[i];
temp2= array[i+1];
array[i+1]=temp1;
array[i+2]=temp2;
i++;
}
array[index]=number;
}
I couldn't figure out how to overwrite 999s or is there a better way instead?