Untitled
unknown
plain_text
8 months ago
651 B
4
Indexable
//deletion at end
#include<iostream>
using namespace std;
void deleteatend(int arr[],int&n,int key){
int pos=-1;
for(int i=0;i<n;i++){
if(arr[i]==key){
pos=i;
}
}
if(pos==-1){
cout<<"element not found"<<endl;
return ;
}
for(int i=pos;i<n;i++){
n--;
}
}
void disp(int arr[],int&n){
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";}
}
int main(){
int arr[8]={1,2,3,4,5};
int n=5;
int key=5;
deleteatend(arr,n,key);
cout<<"array after deletion"<<endl;
disp(arr,n);
return 0;
}
Editor is loading...
Leave a Comment