Programming Fundamentals

Download list_increasing.c here

Or, copy these file(s) to your CSE account using the following command:

1511 fetch-activity list_increasing

Your task is to add code to this function in list_increasing.c:

int increasing(struct node *head) {

    // PUT YOUR CODE HERE (change the next line!)
    return 42;

}

increasing is given one argument, head which is the pointer to the first node in a linked list.

Add code to increasing so that its returns 1 if the list is in increasing order - the value of each list element is larger than the element before.

For example if the linked list contains these 8 elements:

1, 7, 8, 9, 13, 19, 21, 42

increasing should return 1 because it is increasing order

Testing

list_increasing.c also contains a main function which allows you to test your increasing function.

This main function:

  1. converts the first set of read integers to a linked list,
  2. assigns a pointer to the first node in the linked list to head,
  3. calls list_increasing(head) and
  4. prints the result.

Do not change this main function. If you want to change it, you have misread the question.

Your list_increasing function will be called directly in marking. The main function is only to let you test your list_increasing function

Examples

dcc list_increasing.c -o list_increasing
./list_increasing
How many numbers in initial list?: 9
1 2 4 8 16 32 64 128 256
1
./list_increasing
How many numbers in initial list?: 6
2 4 6 5 8 9
0
./list_increasing
How many numbers in initial list?: 6
13 15 17 17 18 19
0
./list_increasing
How many numbers in initial list?: 2
2 4
1
./list_increasing
How many numbers in initial list?: 1
42
1
./list_increasing
How many numbers in initial list?: 0
1

Assumptions/Restrictions/Clarifications