CSci 230: Computing systems organization
Home Syllabus Readings Assignments Tests

printable version

Test 2

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

Problem X2.1.

[12 pts] Suppose we have declared a C struct as below for representing a linked list's node.

struct node {
    int value;
    struct node *next;
};

Complete the following function so that finds the first node whose value is find and inserts a new node following it containing insert. Thus if our list contains three nodes whose values are 2, 3, 5, and we are told to find 3 and insert 4 after it, then after calling the function the list would containing 2, 3, 4, 5.

You may assume that find is actually present in the list. If find appears multiple times, then you would want to insert after just the first occurrence of find.

void list_insert_after(struct node *headint findint insert) {