Skip to content

Commit 96df9cb

Browse files
authored
Update 06 Deleting element from array.c
1 parent c07903c commit 96df9cb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Array/06 Deleting element from array.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ The Arrow(->) operator exists to access the members of the structure or the unio
2626
int i;
2727
if (index>=0 && index <arr->length)
2828
{
29-
x=arr->A[index]; // first of all take out the element from the particular index you want to del
29+
x=arr->A[index]; // first of all take out the element from the particular index you want to del---------------------> taking 1 unit of time
3030
for (i=index;i<arr->length-1;i++) // shift the element in forward direnction and stop at length -1 so that array can not have any vacant space
3131
arr->A[i]=arr->A[i+1]; // at the place of a[i] copy the next element i.e a[i+1]
32-
arr->length--;//at last the length will be decreatmented
32+
arr->length--;//at last the length will be decreatmented ----------------> 1 unit of time -------> so best time is 1+1 =2
33+
34+
// min shifting is 0 and max shifting is n ----> Best case time is O(1) -> Worst Case time is ----> O(n)
3335
return x;
3436
}
3537
return 0;

0 commit comments

Comments
 (0)