#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
int data;
struct Node *next;
} Node;
Node *createList() {
Node *head = (Node *)malloc(sizeof(Node));
head->next = NULL;
return head;
}
void insert(Node *head, int data) {
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->data = data;
newNode->next = head->next;
head->next = newNode;
}
void deleteMinNode(Node *head) {
if (head == NULL || head->next == NULL) {
return;
}
Node *minPrev = NULL;
Node *minNode = head->next;
Node *prev = head;
Node *cur = head->next;
while (cur != NULL) {
if (cur->data < minNode->data) {
minNode = cur;
minPrev = prev;
}
prev = cur;
cur = cur->next;
}
minPrev->next = minNode->next;
free(minNode);
}
int main() {
Node *head = createList();
insert(head, 5);
insert(head, 3);
insert(head, 7);
insert(head, 1);
insert(head, 9);
deleteMinNode(head);
Node *cur = head->next;
while (cur != NULL) {
printf("%d ", cur->data);
cur = cur->next;
}
printf("\n");
return 0;
}