编辑代码

#include <stdio.h>
#include <stdlib.h>

typedef struct Node {
    char data;
    struct Node* next;
} Node;

typedef struct LinkedList {
    Node* head;
} LinkedList;

// 初始化链表
void initializeList(LinkedList* list) {
    list->head = NULL;
}

// 在链表末尾插入元素
void insertElement(LinkedList* list, char data) {
    Node* newNode = (Node*)malloc(sizeof(Node));
    newNode->data = data;
    newNode->next = NULL;

    if (list->head == NULL) {
        list->head = newNode;
    } else {
        Node* current = list->head;
        while (current->next != NULL) {
            current = current->next;
        }
        current->next = newNode;
    }
}

// 删除链表中的第二个元素
void deleteSecondElement(LinkedList* list) {
    if (list->head == NULL || list->head->next == NULL) {
        return;
    }

    Node* second = list->head->next;
    list->head->next = second->next;
    free(second);
}

// 判断链表是否为空
int isListEmpty(LinkedList* list) {
    return (list->head == NULL);
}

// 输出链表内容
void printList(LinkedList* list) {
    Node* current = list->head;
    while (current != NULL) {
        printf("%c ", current->data);
        current = current->next;
    }
    printf("\n");
}

int main() {
    LinkedList list;
    initializeList(&list);

    // 在链表末尾插入元素
    insertElement(&list, 'a');
    insertElement(&list, 'b');
    insertElement(&list, 'c');

    // 删除链表中的第二个元素
    deleteSecondElement(&list);

    // 判断链表是否为空并输出链表内容
    if (!isListEmpty(&list)) {
        printList(&list);
    }

    return 0;
}