[C] Linked list

typedef struct node {
int val;
struct node* next;
} Node;
Node* create_list(int arr[], int len){
if(!arr || len == 0)
return NULL;

Node *head, *tail;
for(int i=0; i<len; i++){
//create node
Node* curr = (Node*)malloc(sizeof(Node));
curr->val = arr[i];
curr->next = NULL;
//if it's first new node
if(i == 0){
head = curr;
tail = curr;
tail->next = curr;
tail = tail->next;

return head;
void print_list(Node* head){
Node* p = head;
printf("%d ", p->val);
p = p->next;
void delete_list(Node* head){
Node* tmp = head;
head = head->next;



Hi I am Samuel

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store