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:
- converts the first set of read integers to a linked list,
- assigns a pointer to the first node in the linked list to
head, - calls
list_increasing(head)and - 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
increasingshould return a single integerincreasingshould not change the linked list it is given. Your function should not change the next or data fields of list nodesincreasingshould not use arraysincreasingshould not callmallocincreasingshould not call scanf (orgetcharorfgets)- You can assume the linked list only contains positive integers
increasingshould not print anything. It should not callprintf- Do not change the supplied
mainfunction. It will not be tested or marked.