Write aprogramm using Array 1,2,3,4,5 and insert middle 5,6 and delete 3
#include <iostream>
using namespace std;
void insert(int *arr, int n, int val) {
arr[n++] = val;
}
void remove(int *arr, int val) {
int n = (int) sizeof(arr) / sizeof(int);
for (int i=0, j=0; j < n; j++) {
if (arr[j] != val)
arr[i++] = arr[j];
}
}
int main() {
int arr[10] = {1,2,3,4,5};
insert(arr, 5, 5);
insert(arr, 6, 6);
remove(arr, 3);
return 0;
}
Comments
Leave a comment