0

I want to delete the first element from a list.

this is my list:

struct dlist {
   int liber; //it translates as "free" don't know what this is
   int nmax; //maximum number of elements 
   DATA *pv; //a pointer with which i can move in list, also DATA is int
};
typedef struct dlist Lista, *LISTA;

//my try so far
//it deletes the first element but you can guess what happens when i reach the last element. I've tried w/o for to no avail.    

void delFirst(LISTA l)
{
    LISTA *temp; int i;
    if(!(empty(l)))
    temp=l->pv[0];
    for(i=0;i<(l->nmax)-1;i++)
        l->pv[i]=l->pv[i+1];

    free(temp);

}

Edited by ogrishmania

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by Ancient Dragon
0

If DATA is defined as int, struct * can not be assigned the value of int without a typecast.

line 19: You can not free() individual elements of an array. The number of elements of an array are fixed when the array is declared and can not be changed. The best you can do is mark the element as unused so that is can be reused when another element needs to be added. That's most likely the purpose of liber.

That temp pointer is not needed. There is no reason to save the value of p[0] since p[0] is nothing more than an integer.

Edited by Ancient Dragon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.