How can i deleat an element from an array (dynamic input) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can i deleat an element from an array (dynamic input)

i want to deleat an element from an array where in put is dynamic ex-: int ar[] = new int[n];

22nd Jan 2017, 4:01 AM
Ravi anshuman
Ravi anshuman - avatar
7 Answers
+ 1
search the element and shift elements. for(I=0;I<n;I++) { if(ar[I]==num) { for(j=I;j<n-1;j++) ar[j]=ar[j+1]; } }
22nd Jan 2017, 4:06 AM
Megatron
Megatron - avatar
+ 1
yes the array still would be n dimensional I am not sure but you can try delete ar[n] if it deletes only nth index.
22nd Jan 2017, 6:49 AM
Megatron
Megatron - avatar
+ 1
@Kamil Sorry I didn't read your answer(question) completely but I think there is no way to change a N-dimensional array to X-dimensional.😂😂😁😁
22nd Jan 2017, 8:15 AM
Megatron
Megatron - avatar
+ 1
I was referring to this one @Megatron wont the array still be n dimensional?
22nd Jan 2017, 8:23 AM
Megatron
Megatron - avatar
0
@Megatron wont the array still be n dimensional?
22nd Jan 2017, 6:46 AM
Kamil Kosyl
Kamil Kosyl - avatar
0
I dont think there is any other way with array than creating new array with m elements and just copy all the values except that one
22nd Jan 2017, 7:58 AM
Kamil Kosyl
Kamil Kosyl - avatar
0
by creating new array I meant new array variable
22nd Jan 2017, 8:20 AM
Kamil Kosyl
Kamil Kosyl - avatar