#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node* next;
};
struct node* head = NULL;
void add_node(int data) {
struct node* new_node = (struct node*)malloc(sizeof(struct node));
new_node->data = data;
new_node->next = head;
head = new_node;
}
void delete_node(int data) {
struct node* temp = head;
struct node* prev = NULL;
while (temp != NULL && temp->data != data) {
prev = temp;
temp = temp->next;
}
if (temp == NULL) {
printf("Node not found\n");
return;
}
if (prev == NULL) {
head = temp->next;
} else {
prev->next = temp->next;
}
free(temp);
}
struct node* find_node(int data) {
struct node* temp = head;
while (temp != NULL && temp->data != data) {
temp = temp->next;
}
return temp;
}
int main() {
add_node(1);
add_node(2);
add_node(3);
struct node* node_to_delete = find_node(2);
delete_node(node_to_delete->data);
struct node* node_to_find = find_node(3);
printf("Found node with data %d\n", node_to_find->data);
return 0;
}