面试题答案
一键面试#include <stdio.h>
#include <stdlib.h>
// 定义链表结构体
struct Node {
int data;
struct Node *next;
};
// 在链表头部插入新节点的函数
void insertNode(struct Node **head, int value) {
// 创建新节点
struct Node *newNode = (struct Node *)malloc(sizeof(struct Node));
if (newNode == NULL) {
printf("内存分配失败\n");
return;
}
newNode->data = value;
newNode->next = *head;
*head = newNode;
}