C
Linked List Activity
Overview
For
this activity you will write a several functions to sort a singly
linked list of integers. Several lists are set up by the driver main().
The
functions you have to write, in order, are:
- struct node *mk_node( v
)
To create a new node with label v
and a NULL
next link and return a pointer to the resulting node.
- void print_list( head
)
Prints the list of values in the list headed by head,
one
value per line.
- struct node *sort( head
)
To sort the list headed by head in
ascending order, and return a pointer to the node that ends up at the
head of the list.
NOTE: You must sort the list by
rearranging the nodes themselves, not by
exchanging the values in the nodes.
- void free_list( head
)
Free all the storage associated with the list of values headed
by head.
Note
that
in real practice on rarely sorts a list in place; this exercise is
primarily to give you an opportunity to work with issues surrounding
list manipulation.
The
Activity
- Download
the source file listsort.c.
- Edit
the file and complete the four functions listed above. Note that the
functions returning pointers have dummy placeholder return statements -
these, of course, must be replaced in the real implementation.
- Note
that if you write the functions in the order given, you can do at least
minimal testing after each function is complete.
Submission
- Your
submission must
be a single source file named exactly listsort.c.
Submit
the file to the ListSort
directory in your repository
Grading
(10 points)
1
Submission
1 mk_node
1
print_list
4
sort_list
1
free_list
2 Quality: Source
files conform to standards of quality implementation &
documentation.