#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node* next;
};

struct node* create_node(int val) {
    struct node* newnode = (struct node*)malloc(sizeof(struct node));
    if (!newnode) {
        printf("Memory allocation failed\n");
        exit(1);
    }
    newnode->data = val;
    newnode->next = NULL;
    return newnode;
}

struct node* delete_node(struct node* head, int val) {
    struct node* temp = head;
    struct node* prev = NULL;

    if (head == NULL)
        return head;

    if (head->data == val) {
        struct node* to_delete = head;
        head = head->next;
        free(to_delete);
        return head;
    }

    while (temp != NULL && temp->data != val) {
        prev = temp;
        temp = temp->next;
    }

    if (temp == NULL)
        return head;

    prev->next = temp->next;
    free(temp);
    return head;
}

void print_list(struct node* head) {
    struct node* temp = head;
    while (temp != NULL) {
        printf("%d ", temp->data);
        temp = temp->next;
    }
    pr