CS209 lab5


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l5.html




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).

  1. 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).
  2. 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).
  3. 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