0
I have a question about a chained list in C. The exercise is a function that takes as parameter the initial node of the chained list and the position x (counting backwards). With this, I have to go through and find the position, return the value of the corresponding node.
I’ve done it so far:
struct Node
{
int data;
struct Node *next;
}
/*-------------------------------------------------*/
int GetNode(Node *head,int positionFromTail)
{
struct Node* fimNodo;
while(head->next!=NULL){
head->next=next;
if(head->next==NULL){
fimNodo->data=head->data;
fimNodo->next=head->next;
}
}
while(positionFromTail!=0){
fimNodo->next=*next;
positionFromTail--;
if(positionFromTail==0){
return fimNodo->data;
}
}
}
You are making a mistake in this role. Could someone help me?
Note: Exercise is only this function and does not require the main function...
The errors that are occurring are:
cannot resolve overloaded function ‘next’ based on conversion to type ‘Node*’
cannot convert ‘Node’ to ‘Node*’ in assignment
could specify which error is occurring?
– mercador
cannot resolve overloaded function ‘next’ based on conversion to type ‘Node*’, base operand of ‘->’ has non-pointer type ‘Node’, base operand of ‘->’ has non-pointer type ‘Node’, base operand of ‘->’ has non-pointer type ‘Node’ , this occurs from the second while.
– Maurício Z.B
Friend, put the error message editing the question. It’s horrible to read code in the comments
– Leonardo Alves Machado
I saw that you updated the code... I edited it now to format it better. But I wonder where the variable is initialized
next
, used at the beginning of loops. If I try to compile, it will give undeclared variable...– Leonardo Alves Machado