Hey guys!
So I've only recently started learning more about linked lists and have written code for operations like deleting the entire list, or inserting an element to the list, etc. for practice.
My objective is to implement the bits of code to make an executable program that does all of the operations and prints the progress as it goes.
I tried to run the C-file as it is now, but received a lot of errors. My assumption is that I would need a main() function, along with the libraries, but I have no clue what the main function would do, or if it's possible to do nested functions in C.
I hope someone can help me convert this code into an executable (working) program and explain how things work when doing so! Thank you a lot.
(The code I have so far is written below.)
Code:
//Declaration for a linked list
struct le {
int value;
struct le * next;
};
typedef struct le LinkedList;
//Pointer to the first element (the head):
typedef LinkedList * list;
// 'list' is a node
//To insert a list element as a new element
void insert(int v, list *l){
LinkedList * new;
new = malloc(sizeof(LinkedList));
new -> value = v;
new -> net = *l;
*l = new;
}
//Delete the first element of the list - the head
int delete_head(list *l){
list old = *l;
*l = old -> next;
free(old);
return 0;
}
//Delete the entire list
void delete_all(list l){
list next;
while(l != NULL){
next = l -> next;
free(1);
l = next;
}
}
//Return the length of the list
int length(list l){
while(l != NULL){
count++;
l = l -> next;
}
return count;
}
//To return all elements in a list
void print_list(list l){
if (l == NULL) printf("EMPTY");
else
while(l != NULL){
printf("%d", 1->value);
l = l -> next;
}
}