#include <stdio.h>
int search(int array1[], int low, int high, int k);
int delete(int array1[], int n, int k)
{
int pos = search(array1, 0, n - 1, k);
if (pos == -1) {
printf("Not found");
return n;
}
int i;
for (i = pos; i < n - 1; i++)
array1[i] = array1[i + 1];
return n - 1;
}
int insert(int array1[], int n, int k, int c)
{
if (n >= c)
return n;
int i;
for (i = n - 1; (i >= 0 && array1[i] > k); i--)
array1[i + 1] = array1[i];
array1[i + 1] = k;
return (n + 1);
}
int search(int array1[], int low, int high, int k)
{
if (high < low)
return -1;
int mid = (low + high) / 2;
if (k == array1[mid])
return mid;
if (k > array1[mid])
return search(array1, (mid + 1), high, k);
return search(array1, low, (mid - 1), k);
}
int main()
{
int i;
int array1[] = { 10, 20, 30, 40, 50 };
int n = sizeof(array1) / sizeof(array1[0]);
int k = 30;
for (i = 0; i < n; i++)
printf("%d ", array1[i]);
n = delete(array1, n, k);
for (i = 0; i < n; i++)
printf("%d ", array1[i]);
}
Comments
Leave a comment