Week 10 Tutorial Questions

  1. In this week's lab please complete the myExperience survey for COMP1511.
  2. Your tutor has asked a lab pair to present their week 9 work.

    Discuss the good, the bad and the ugly aspects of their code.

    Please be gentle in any criticism - we are all learning!

  3. It's week 10! Well done on making it this far through the course, you've all worked very hard, and achieved some incredible results, and you should all feel proud about how far you've come in these ten short weeks. Take some time as a tute to look back over the semester, and think about how it has been for you. What were your favorite parts? What things weren't so good? And perhaps most importantly, who/what are you grateful for?
  4. How are you progressing with the assignment?

    Do you have any questions? Have you learned anything that would be useful to share with the rest of the tutorial?

  5. What is the purpose of a Header file?
  6. What is the purpose of a Implementation file?
  7. I have two files, a list.h and a list.c that describe a particular form of list that I want to use.

    I then have a main.c that would like to use the functionality offered by the other two files.

    Which files need to #include the other files?

    What is the compilation command that will combine these files into a single program?
  8. What is a queue?
  9. Draw a diagram of a queue, if it was implemented by a Linked List. Show:
    • How the linked list is structured, with a head pointer and pointers between nodes
    • Which end of the list is the front and back of the queue
    • Any extra structure(s) that might be needed to manage the queue
    • What happens when a new object is added to the queue
    • What happens when an object is removed from the queue
  10. Keeping the same diagram, show what changes you'd need to make to turn this structure into a stack?
  11. Given the abstract structure you have drawn for a queue, write the code that will represent your queue as well as the function to add an element to the queue.

    You will need to show what code goes in the header file and what code goes in the implementation file.

    We can assume that the data we're holding in each element of the queue is an integer.

    You might like to use the following activity as a starting point.

    Given the starter code below, complete these steps to implement and use a queue ADT.

    • Which 3 files do we need? What are the names of these files?
    • Which code belongs in which files?
    • Complete the implementation file
    • Create a file that uses the code. Should we use the following line in this file?
      printf("%d\n", q->start->data);
        typedef struct queueInternals *Queue;
        void enqueue(Queue q, int item);
        int dequeue(Queue q);
        Queue newQueue(void);
        int main(void) {
            //TODO: Add some code that makes a queue
        }
        struct queueInternals {
            struct queueNode *front;
            struct queueNode *back;
        };
        struct queueNode {
            int data;
            struct queueNode *next;
        };
        Queue newQueue(void){
            //TODO: Implement  
        }
        // Add a queueNode to the end of the list (just after back)
        void enqueue(Queue q, int item) {
            //TODO: Implement
        }
        //Remove a queueNode from the beginning of the list (at the start) and return
        // the value of data at the start node
        int dequeue(Queue q){
            //TODO: Implement
        }