LINKED LIST IN C - BASICS :D

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

/*FUNCTION PROTOTYPES*/

/*I define the information field structure..
It can be a simple integer value but we can define it as a structured type*/
struct SInfo{
int value;
};

/*I define a new data type called 'TInfo' of SInfo type*/
typedef struct SInfo TInfo;

/*I create list node structure*/
struct SNode{
/*Information field in the list node*/
TInfo info;
/*pointer to the next node*/
struct SNode *next;
};

/*I define a new var type called 'TNode' of SNode type*/
typedef struct SNode TNode;

/*I define a pointer to TNode called TList*/
typedef TNode *TList;

/*Return list pointer, create a new list*/
TList create_list();


TInfo read_info();
TList insert_element(TList,TInfo);
TList delete_list(TList);
void print_list(TList);

int main(){
int i,n;
TList first;
TInfo info;

printf("\t\t\tLIST EXERCISE!\n");

printf("Insert elements number :");
scanf("%d",&n);

first=create_list();

for(i=0;i<n;i++){

info = read_info();

first = insert_element(first,info);

}

print_list(first);

first = delete_list(first);

fflush(stdin);
getchar();
}

/*FUNCTION DECLARATION*/

TList create_list(){
return NULL;
}

TInfo read_info(){
TInfo info;
printf("Insert number :");
scanf("%d",&info.value);
return info;
}
/*Sorted elements inserting*/
/*
F!: Position search
F2: Dinamic allocation
F3: Pointers updating*/

TList insert_element(TList first,TInfo info){
TList prec,current,newnode;

prec=NULL;
current=first;

/*F1: Posittion search */
while(current!=NULL && info.value > current->info.value ){
prec=current;
current=current->next;
}

/*F2: Dinamic allocation*/
newnode=(TNode *)malloc(sizeof(TNode));
/*Control allocation outcame*/
assert(newnode!=NULL);

newnode->info=info;

/*F3:Pointers updating */
if(prec==NULL){
newnode->next=first;
first=newnode;
return first;
}else{
prec->next=newnode;
newnode->next=current;
return first;
}


}

void print_list(TList first){
TList current;

current=first;
printf("\n");

while(current!=NULL){
printf("\t%d",current->info.value);
/* pointer incrementation */
current=current->next;
}

}

TList delete_list(TList first){
TList current,success;

current=first;

while(current!=NULL){

success=current->next;

free(current);

current=success;

}

return NULL;

}