Week 10 Tutorial Questions

    Looking back

  1. In this week's lab please complete the myExperience survey for COMP1511.

    Previous feedback has changed the way we run weekly tests, and helped us re-arrange content in the course to be most useful. Your tutor may also have some examples of good feedback they have received.

  2. 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 term, 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?

  3. 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?

    If you have any questions, feel free to ask in the lab, on the forums or in the help sessions.

  4. Abstract data types

  5. What is an abstract data type? What are some examples?

  6. Why do we use abstract data types? In what situations, do we use ADTs?

  7. Stacks

  8. What is a stack?

  9. Draw a diagram of a stack, if it was implemented by a Linked List. Show:

    • How the linked list is structured, with a head pointer and pointers between nodes
    • Any extra structure(s) that might be needed to manage the stack
    • What happens when a new object is added to the stack
    • What happens when an object is removed from the stack
  10. Will a stack always be implemented using a linked list?

  11. For the next few questions, you have been provided 3 files.
    list.c
    list.h
    main.c

    list.c contains many linked list functions that have already been implemented. list.h contains definitions for these functions.

  12. What functions in list.h may be useful for implementing the idea of a stack?
  13. Write a program using the provided files that will compile into a binary named pancake. This program deals with a hungry customer that seems to have no end to their ravenous rampage on the stack of pancakes before them.

    Your job is to keep stacking up their plate as they eat their pancakes one at a time

    Some starter code has been provided in main.c as well as an indicator on where to put your code. You will simply be implementing the commands noted in the function by utilising the list.h functions.

    dcc list.c main.c -o pancake
    ./pancake
    a Regular Pancake
    Added: Regular Pancake
    a Choc-Chip Pancake
    Added: Choc-Chip Pancake
    a Banana Pancake
    Added: Banana Pancake
    p
    Banana Pancake
    Choc-Chip Pancake
    Regular Pancake
    e
    The customer has eaten Banana Pancake
    p
    Choc-Chip Pancake
    Regular Pancake
    a Banana Pancake
    Added: Banana Pancake
    a Banana Pancake
    Added: Banana Pancake
    a Choc-Chip Pancake
    Added: Choc-Chip Pancake
    p
    Choc-Chip Pancake
    Banana Pancake
    Banana Pancake
    Choc-Chip Pancake
    Regular Pancake
    e
    The customer has eaten Choc-Chip Pancake
    e
    The customer has eaten Banana Pancake
    e
    The customer has eaten Banana Pancake
    e
    The customer has eaten Choc-Chip Pancake
    e
    The customer has eaten Regular Pancake
    e
    The customer has reached the plate! You cannot eat that!
    
  14. Recursion

  15. What is recursion?

  16. Using an iterative approach, implement a function minimum which is given a linked list struct node *head, returns the minimum of the linked list as an integer.

    If given an empty list, return INT_MAX which is defined in limits.h.

    minimum should have this prototype:

    int minimum(struct node* head);
    
  17. Using a recursive approach, implement a function minimum which is given a linked list struct node *head, returns the minimum of the linked list as an integer.

    If given an empty list, return INT_MAX which is defined in limits.h.

    minimum should have this prototype:

    int minimum(struct node* head);
    
  18. Using an iterative approach, implement a function print_string_reverse which prints a string in reverse.

    print_string_reverse should have this prototype:

    void print_string_reverse(char *string);
    
  19. Using a recursive approach, implement a function print_string_reverse which prints a string in reverse.

    print_string_reverse should have this prototype:

    void print_string_reverse(char *string);