Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Deleting node in list

*x = L->list[i];      /* Save the deleted element to parameter x */
for(j = i+1; j <= L->size-1; j++)
L->list[i] = L->list[i+1];
L->size--;            /* The number of data elements is reduced by 1*/
return 1;

I cant delete the node fully, instead of this, its just replacing the value, but the node itself is not deleted

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Within this for loop

for(j = i+1; j <= L->size-1; j++)
L->list[i] = L->list[i+1];

the variable i used in this statement

L->list[i] = L->list[i+1];

is not being changed.

It seems you mean

for(j = i+1; j < L->size; j++)
    L->list[j-1] = L->list[j];

If the array list is allocated dynamically then you should reallocate it as for example

for(j = i+1; j < L->size; j++)
    L->list[j-1] = L->list[j];
L->size--;

T *tmp = realloc( L->list, L->size * sizeof( *tmp ) );
if ( tmp != NULL ) L-:list = tmp );

You will need to substitute T with the actual type of elements of the array. I am using T because it is unknown from your question what is the type of elements of the array.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading