added deletion
This commit is contained in:
parent
b031c99b8d
commit
af49266f25
26
cs161BW4/delete.cpp
Normal file
26
cs161BW4/delete.cpp
Normal 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;
|
||||
}
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user