Here is the exercise:
Write a function called insertEntry to insert a new entry into a linked list. Have the procedure take as arguments a pointer to the list entry to be inserted(of type struct entry) and a pointer to an element in the list AFTEr which the new entry is to be inserted.
My preliminary work, NOT FINISHED, is resulting in no out put to the console window. Before I implement the actual function I just want to make sure I'm doing it right without using the function. And I dunny know why. *scrathes head*
Code:
#include <stdio.h>
struct entry
{
int values;
struct entry *next;
};
/* void insertEntry(struct entry *list_entry,struct entry *later_entry)
{
list_entry=&later_entry)
} */
struct entry n1,n2,n3,n2_3;
int i;
int main(void)
{
struct entry *list_pointer=&n1;
n1.values=100;
n1.next=&n2;
n2.values=200;
n2.next=&n3;
n3.values=300;
n3.next=(struct entry *)0;
n2_3.values=250;
while(list_pointer !=(struct entry *) 0);
{
printf("%i\n",list_pointer->values);
list_pointer=list_pointer->next;
}
list_pointer=&n1;
n2_3.next=n2.next;
n2.next=&n2_3; // Remove for function?
// insertEntry(&n2_3,&n3);
printf("\nAfter entry insertion:\n");
while(list_pointer !=(struct entry *) 0)
{
printf("%i\n",list_pointer->values);
list_pointer=list_pointer->next;
}
getchar();
return 0;
}