Pointer Notation With Linked Lists
#include <stdio.h>;
typedef struct node
{
int info;
struct node *link;
} NODE;
void insert_front(NODE **ptr, NODE *new_one);
void print_list(NODE *ptr);
int main(void)
{
NODE *front = NULL;
NODE *new_one;
/**
gets the memory for new_node - a function to do this is needed
get_memory(&new_one);
**/
new_one = (NODE *)malloc(sizeof(NODE));
new_one->info = 1;
new_one->link = NULL;
/**
front = new_one; if the list is empty, this actually puts the new node
at the front of the list.
**/
insert_front(&front, new_one);
print_list(front);
return (0);
}
/** This function currently only deals with the empty list **/
void insert_front(NODE **ptr, NODE *new_one)
{
if (*ptr == NULL)
*ptr = new_one;
else
{
/* set pointer field in new_one to the pointer field in the first
node of the list
set *ptr to new_one
*/
}
}
void print_list(NODE *start)
{
if (start == NULL)
{
printf("\nList is empty.\n");
}
else
{
printf("\n");
while(start != NULL)
{
printf("%d ", start->info);
start = start->link;
}
}
}