added deletion

This commit is contained in:
clarissa 2023-10-17 10:48:15 -07:00
parent b031c99b8d
commit af49266f25
2 changed files with 27 additions and 0 deletions

26
cs161BW4/delete.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
using namespace std;
//my solution
void deleteArr(int arr[], int index, int &count){
for(int i = index; i < count-1; i++){
arr[i] = arr[i+1];
}
count = count - 1;
}
int main(){
int arr1[] = {0,1,2,3,4};
int a1size = 5;
deleteArr(arr1,0,a1size);
deleteArr(arr1,3,a1size);
// should be {1,2,3} at the end
// a1size should be 3
for(int i = 0; i < a1size; i++){
cout << arr1[i] << " ";
}
cout << endl;
cout << a1size << endl;
return 0;
}

View File

@ -6,6 +6,7 @@
** Talk about inserting elements into an array
** Generic insert with templates
** Deleting elements of an array
*** Exercise for you
** Generic delete with templates
** Multi-dimensional array practice
** Lab time