My List is implemented via these two structs. The first contains the items in the list while the second contains the list itself.
typedef Employee Item;
typedef struct ListNodeTag {
Item item;
struct ListNodeTag *next;
} ListNode;
typedef struct {
int size;
ListNode *first;
} List;
I am trying to use the following recursive function to reverse the contents of the list however, I am getting a segmentation fault once there is more than one item in the list.
void Reverse(List *L){
ListNode *q,*p;
q = L->first;
p = q->next;
if(p == NULL)
return;
Reverse(L);
q->next->next = q;
q->next = NULL;}
I believe that the issue lies in the fact that instead of passing a member of the list as a function argument I am passing a pointer to the list itself. How would I change this code to let it work without passing a different argument?