数据结构最基础的一段代码,包含以下对单项链表的处理
- List item
创建,插入,查找,删除,排序(交换节点),排序(交换数据),
销毁,双向循环链表,创建.插入,查找,删除,排序(交换节点),
排序(交换数据),销毁
——01testlist.c
#include "01testlist.h"
#include <stdio.h>
Node * createList() //创建
{
Node *head = (Node*)malloc(sizeof(Node));
head->next = NULL;
return head;
}
void insertList(Node * head, int data) //插入
{
Node * cur = malloc(sizeof(Node));
cur->data = data;
cur->next = head->next;
head->next = cur;
}
void traverseList(Node *head) //遍历
{
head = head->next;
while (head)
{
printf("%d ",head->data);
head = head->next;
}
}
int lenList(Node *head) //统计
{
i