CS209 lab5
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l5.html
-
For this lab you should submit all source code (C
files), and the result(s) of running the program on (a few)
test cases.
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code).
-
The above material should be uploaded via BLACKBOARD
before
the deadline of 5pm
Wednesday 2nd. March 2011. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/
This lab is based on using structures and pointers in C to
do manipulations on linked lists.
The starting point for the lab is the program test.c at
http://www.maths.nuigalway.ie/~gettrick/teach/cs209/progs/test.c:
You should study this program, save it and run it (it is pretty much the one described in lectures).
-
Modify the code so that a points to c and c points to b. Use printf
to print the values of
-
&(c.data)
-
&(c.n)
-
(*(c.n)).data
-
(b.data)
Are any of these values the same? (Include the actual values printed out when you hand in your
lab - you can do this by just uploading a separate text file, or indeed by typing this
information in to the C program as comments).
-
Modify the code so that a links to itself, b links to c and c links to b. Print out the
values of
-
a.n
-
&(a.n)
-
(*(a.n)).data
-
a.data
-
c.data
-
(*(*(c.n)).n).data
Are any of these values the same? (Again, include the actual values printed out when you hand in your
lab - you can do this by just uploading a separate text file, or indeed by typing this
information in to the C program as comments).
-
Change the list structure to be a doubly linked list: In this new structure
you will have int data, struct list *n (a pointer that points
"to the right") and struct list *p (a pointer that points
"to the left"). In this way, connect a, b and c "in a circle" (a points to the right to b, and
to the left to c, etc.).
Having done this, add in a fourth element d containing the number 4 between a and c in
the doubly linked list.
©
NUI, Galway