COMP1721 - Higher Computing 1B

Computing 1B - Week 09 Tutorial Questions

  1. These types are used to represent an ordered sequence of integer values as a linked list:
    typedef struct list_node list_node;
    typedef list_node *linked_list;
    
    struct list_node {
        int       data;
        list_node *next;
    };
    

    Write a function which tests if a specified value is a found in a specified list, i.e. the function should return 1 if the value occurs in the list 0 otherwise. Your functions should have this prototype:

    int member(int value, linked_list list);
    

  2. These types are used to represent an ordered sequence of integer values as a linked list:
    typedef struct list_node list_node;
    typedef list_node *linked_list;
    
    struct list_node {
        int       data;
        list_node *next;
    };
    

    Write a function which takes a string containing a list of integers in Haskell syntax, e.g "[3,42,-5]", and returns the equivalent linked list. Your function should have this prototype:

    linked_list string_to_list(char *s);
    

  3. These types are used to represent an ordered sequence of integer values as a linked list:
    typedef struct list_node list_node;
    typedef list_node *linked_list;
    
    struct list_node {
        int       data;
        list_node *next;
    };
    

    Write a function which takes a linked list returns a string describing the list in Haskell syntax. The string should be malloc'ed. Your function should have this prototype:

    char *list_to_string(linked_list list);
    


Andrew Taylor (andrewt@cse.unsw.edu.au)
Higher Computing 1B, Computer Science & Engineering, UNSW