提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
typedef struct Node { int data; struct Node* next; }Node; //创建空链表 Node* creatList() { Node* list = (Node*)malloc(sizeof(struct Node)); if (list == NULL) return NULL; list->next = NULL; return list; }
代码如下(示例):
//插入节点(头插法) void insertNode_head(Node** list,int data) { Node* newNode = creatNode(data); newNode->next = (*list)->next; (*list)->next = newNode; } //插入节点(尾插法) void insertNode_trail(Node** list, int data) { Node* newNode = creatNode(data); Node* pMove = (*list); while (pMove->next) { pMove = pMove->next; } pMove->next = newNode; }
代码如下(示例):
#include<stdio.h> #include<malloc.h> typedef struct Node { int data; struct Node* next; }Node; //创建空链表 Node* creatList() { Node* list = (Node*)malloc(sizeof(struct Node)); if (list == NULL) return NULL; list->next = NULL; return list; } //创建节点 Node* creatNode(int data) { Node* list = (Node*)malloc(sizeof(Node)); if (list == NULL) return NULL; list->data = data; list->next = NULL; return list; } //插入节点(头插法) void insertNode_head(Node** list,int data) { Node* newNode = creatNode(data); newNode->next = (*list)->next; (*list)->next = newNode; } //插入节点(尾插法) void insertNode_trail(Node** list, int data) { Node* newNode = creatNode(data); Node* pMove = (*list); while (pMove->next) { pMove = pMove->next; } pMove->next = newNode; } //打印链表 void printList(Node* list) { Node* pMove = list->next; while (pMove) { Node* q = pMove; printf("%d ", pMove->data); pMove = pMove->next; free(q);//释放 } } int main() { Node* list1 = creatList(); Node* list2 = creatList(); for (int i = 0; i <= 5; i++) { insertNode_head(&list1, i); insertNode_trail(&list2, i); } printList(list1); putchar('\n'); printList(list2); return 0; }
代码如下(示例):
在这里插入代码片
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
3. 循环链表