Introduction
We will test your code using the gcc compiler.
Unless otherwise stated, lists will be singly-linked, made of sNodes:
typedef struct sNode sNode;
struct sNode
{
int data;
sNode* next;
}
The Exercises
1. Write a function that takes a list, returns its length. You may assume that it contains no cycles.
size_t listLength(const sNode *L );
Q1 Place your function, with function header comments, in your labsheet, with formatting. Consider
Vim's :r (read) command, or use Bash redirect/append.
2. Write a function that reverses a list, in place. That is, you will not allocate any more heap memory, just modify the next points of the
existing nodes. Return pointer to new list.
sNode* listRev(sNode *L);
I'd recommend three pointers, keep track of the previous, and the next. You'll have a border case to deal with, perhpas two.
Q2 Place the function in your labsheet, with formatting. Consider Vim's :r (read) command, or use Bash
redirect/append.