I'm struggling with what might seem a very simple question about linked lists in C. Here it goes:
I need to print a reverse linked list with a space between elements. After printing the last (in this case, first) element I have to break page instead of printing a space. So it would be something as the following:
Linked List: [1,2,3,4]
Expected Output: 4 3 2 1\n
I am aware that I have to store information from the first element in order to create a conditional structure to implement what the question asks. However, since I'm using recursion I've got no clue how.
Here's the state of my current function:
void print_list(LinkedNode *start)
if(start == NULL){
return;
}
print_list(start->next);
printf("%d ", start->data);
return;
And here's the struct of the list:
typedef struct LinkedNode LinkedNode;
struct LinkedNode {
int data;
LinkedNode *next;
};
Also note that I cannot use any header besides stdio.h and stdlib.h.
I almost forgot to mention but this is my first question here so I would really appreciate any tips around.
Thanks in advance!