Heres something to start you off:
Code:
#include <stdio.h>
struct node {
int data;
struct node* next;
};
void insert(struct node** head, int key);
void print_list(struct node* head);
int main(int argc, char **argv)
{
struct node* list = NULL;
insert(&list,5);
insert(&list,7);
insert(&list,2);
print_list(list);
return 0;
}
void insert(struct node** head, int key)
{
struct node** current = head;
while (*current != NULL)
{
/* traverse the list */
current = &((*current)->next);
}
/* make new node and re-link */
struct node* new = (struct node*)malloc(sizeof(struct node));
new->data = key;
new->next = *current;
*current = new;
}
void print_list(struct node* head)
{
while (head != NULL)
{
/* print and traverse the list */
printf("%d ",head->data);
head = head->next;
}
return;
}
This basically demonstrates the basic functions of a linked list, obviously you can create more functions such as delete() etc. I've also added in a print function so you can verify that it works properly. Now you'll probably want to create another function that takes both an array and a linked list pointer (struct node*) and copies from the array to the linked list using the insert() function I have above.
Hope that helps you point to the right direction.