Operations in a Sorted Array
Inserting in a sorted array, checking if an array is sorted and shifting negative elements to the left of array.
Inserting in a Sorted Array :
void insertInSorted(int a[], int n, int x) {
int i = n-1; // Shift from right
// Shifting elements to the right
while (i >= 0 && a[i] > x) {
a[i+1] = a[i];
i--;
}
// Inserting element in proper position
a[i+1] = x;
}Checking if an Array is Sorted :
Rearranging an Array
Last updated