#include <stdio.h>
#include <stdlib.h>
typedef struct Data {
int value;
struct Data *next;
} Data;
Data* insert(Data* head, int value) {
Data* new_node = (Data*)malloc(sizeof(Data));
new_node->value = value;
new_node->next = head;
return new_node;
}
Data* reconnect(Data* head, int value) {
if (head == NULL || head->value == value) return head;
Data *prev = NULL, *curr = head;
while (curr != NULL && curr->value != value) {
prev = curr;
curr = curr->next;
}
if (curr != NULL && prev != NULL) {
prev->next = curr->next;
curr->next = head;
head = curr;
}
return head;
}
int main() {
Data *head = NULL, *curr;
for (int i = 1; i <= 5; i++)
head = insert(head, i);
head = reconnect(head, 3);
for (curr = head; curr != NULL; curr = curr->next)
printf("%d", curr->value);
return 0;
}
To embed this project on your website, copy the following code and paste it into your website's HTML: