No, that part of the code appears to be correct. What is happening is that prev is stepping through the linked list as it is being built. prev = current fixes that.
No, that part of the code appears to be correct. What is happening is that prev is stepping through the linked list as it is being built. prev = current fixes that.
i know thats logical but whats puzzling me is we now allocating memory right in this loop iteration so when we allocate by malloc that memory gets passed to both prev and current i tried to remove prev it didnt work coz prev points to previous member i think but what i dont understand is how it works ....
so basically here first time loop runs perv gets assigned to current then after that on 2nd time when loops runs it sets perv->next which sets perv->next to previous next of current right ?