用双向链表实现字符串逆序输出的代码
以下是一个用C语言编写的双向链表,将字符串逆序输出的程序的示例。\n\n```\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\ntypedef struct node {\n char data;\n struct node* next;\n struct node* prev;\n} Node;\n\nvoid insert(Node* head, char data) {\n Node* new_node = (Node*)malloc(sizeof(Node));\n new_node->data = data;\n new_node->next = head->next;\n new_node->prev = head;\n head->next->prev = new_node;\n head->next = new_node;\n}\n\nvoid reverse(Node* head) {\n Node *current = head->next, *temp;\n while (current != head) {\n temp = current->next;\n current->next = current->prev;\n current->prev = temp;\n current = temp;\n }\n temp = head->next;\n head->next = head->prev;\n head->prev = temp;\n}\n\nvoid print(Node* head) {\n Node* current = head->next;\n while (current != head) {\n printf(\c\ current->data);\n current = current->next;\n }\n printf(\n\}\n\nint main() {\n char* str = \hello world\ int len = strlen(str);\n Node* head = (Node*)malloc(sizeof(Node));\n head->next = head;\n head->prev = head;\n for (int i = len - 1; i >= 0; i--) {\n insert(head, str[i]);\n }\n printf(\Original: %s\\n\ str);\n printf(\Reversed: \ reverse(head);\n print(head);\n return 0;\n}\n```\n\n此程序使用双向链表来存储和操作字符串,将字符串中的字符倒序插入到链表中,然后翻转链表并输出其中的字符,从而实现将字符串逆序输出的功能。