#include <stdio.h>
struct entry
{
int value;
struct entry * next;
};
int main()
{
void insertEntry(struct entry * list_pointer, struct entry * prev);
struct entry *list_pointer, *prev;
struct entry n1, n2, n3, n4;
n1.value = 100;
n1.next = &n2;
n2.value = 200;
n2.next = &n3;
n3.value = 300;
n3.next = &n4;
n4.value = 400;
n4.next = (struct entry *) 0;
list_pointer = &n1;
prev = &n2;
while (list_pointer != (struct entry *) 0) {
printf("%i \n", list_pointer
->value
); list_pointer = list_pointer->next;
}
insertEntry(list_pointer, prev);
list_pointer = &n1;
while (list_pointer != (struct entry *) 0) {
printf("%i\n", list_pointer
->value
); list_pointer = list_pointer->next;
}
return 0;
}
void insertEntry(struct entry * list_pointer, struct entry * prev)
{
struct entry newEntry;
newEntry.value = 555;
while (list_pointer != (struct entry *) 0) {
if (list_pointer == prev) {
newEntry.next = list_pointer;
list_pointer->next = &newEntry;
}
else
list_pointer = list_pointer->next;
}
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgpzdHJ1Y3QgZW50cnkKewoJaW50IHZhbHVlOwoJc3RydWN0IGVudHJ5ICogbmV4dDsKfTsKCmludCBtYWluKCkKewoJdm9pZCBpbnNlcnRFbnRyeShzdHJ1Y3QgZW50cnkgKiBsaXN0X3BvaW50ZXIsIHN0cnVjdCBlbnRyeSAqIHByZXYpOwoJc3RydWN0IGVudHJ5ICpsaXN0X3BvaW50ZXIsICpwcmV2OwoJc3RydWN0IGVudHJ5IG4xLCBuMiwgbjMsIG40OwoJbjEudmFsdWUgPSAxMDA7CgluMS5uZXh0ID0gJm4yOwoJbjIudmFsdWUgPSAyMDA7CgluMi5uZXh0ID0gJm4zOwoJbjMudmFsdWUgPSAzMDA7CgluMy5uZXh0ID0gJm40OwoJbjQudmFsdWUgPSA0MDA7CgluNC5uZXh0ID0gKHN0cnVjdCBlbnRyeSAqKSAwOwoJbGlzdF9wb2ludGVyID0gJm4xOwoJcHJldiA9ICZuMjsKCglwcmludGYoIkJlZm9yZTogXG4iKTsKCgl3aG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