Salve, devo implementare uno stack mediante liste concatenate, il mio problema è che non riesco ad accedere al campo data del nodo.
typedef struct StackLst StackLst;
struct StackLst {
DataObject *data;
StackLst *next;
};
void* constructStackLst()
{
StackLst *stkLst=(StackLst*)malloc(sizeof(StackLst));
if(stkLst!=NULL)
{
stkLst->data=NULL;
stkLst->next=NULL;
}
else
{
("ERRORE: MEMORIA NON DISPONIBILE");
}
return stkLst;
}
void pushStackLst(void *stkHead,DataObject *dataObj)
{
StackLst *head=(StackLst*)stkHead;
StackLst *newNode=(StackLst*)malloc(sizeof(StackLst));
newNode->data=adtClone(dataObj);
newNode->next=head;
head=newNode;
}
Da qui in avanti quando cerco di accedere al campo data di un nodo (ad esempio nella funzione top) mi da segmentation fault, qualcuno sa dirmi il perche?
DataObject* topStackLst(void *stkHead)
{
StackLst *head=(StackLst*)stkHead;
DataObject *top=adtClone(head->data);
return top;
}