#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>typedef struct Node {int data;  //数据域struct Node * pNext;   //指针域}Node, *pNode;//函数声明
pNode create_list();
void traverse_list(pNode  pHead);
int main(void) {pNode  pHead = NULL;   //等价于 struct Node *pHead=NULLpHead = create_list();    //create_list()创建一个非循环单链表,并将该链表的头结点的地址赋给pHeadtraverse_list(pHead);while(true){}return 0;
}//创建单链表
pNode create_list() {int len;   //用来存放有效节点数int i;int val; //存放用户临时输入的节点数据//我们首先要先生成一个头结点  不存放有效数据pNode pHead = (pNode)malloc(sizeof(Node));if (NULL == pHead) {printf("内存分配失败");//程序退出exit(-1);}pNode pTail = pHead;    //pTail也指向了头结点pTail->pNext = NULL;printf("请输入你要输入节点的个数 len =");scanf_s("%d", &len);//假设输入的长度5,我们需要循环for ( i = 0; i < len; i++){printf("请输入第%d个节点的值:", i + 1);scanf_s("%d", &val);pNode pNew=(pNode)malloc(sizeof(Node));if (NULL == pNew) {printf("内存分配失败");//程序退出exit(-1);}pNew->data = val;//pHead->pNext = pNew;//pNew->pNext = NULL;pTail->pNext = pNew;  //将这个新节点挂到尾节点,新节点最后一个节点pNew->pNext = NULL;   //将最后一个节点的指针域置空pTail = pNew;         //将新节点赋给最后的一个节点 pTail }return pHead;
}//遍历
void traverse_list(pNode  pHead) {pNode p = pHead->pNext;while (p!=NULL){printf("%d ",p->data);p = p->pNext;}//换行printf("\n");return;
}
求一个链表的长度和判断一个链表是否为空
#include <stdio.h>
#include <malloc.h>
#include <string.h>
#include <stdlib.h>typedef struct Node {int data;  //数据域struct Node * pNext;   //指针域}Node, *pNode;//函数声明
pNode create_list();
void traverse_list(pNode  pHead);bool is_empty(pNode pHead);          //判断链表是否为空
int length_list(pNode pHead);        //链表的长度
bool insert_list(pNode, int, int);   //插入  第一个参数表示插入的链表  第二个参数表示插入的位置  第三个参数表示插入的元素
bool delete_list(pNode, int, int *); //第一个参数表示要删除的位置,第二个参数表示要删除的位置 第三参数表示删除的元素的地址放入指针
void sort_list(pNode);int main(void) {pNode  pHead = NULL;   //等价于 struct Node *pHead=NULLpHead = create_list();    //create_list()创建一个非循环单链表,并将该链表的头结点的地址赋给pHeadtraverse_list(pHead);int len = length_list(pHead);printf("链表的长度%d\n", len);while(true){}return 0;
}//创建单链表
pNode create_list() {int len;   //用来存放有效节点数int i;int val; //存放用户临时输入的节点数据//我们首先要先生成一个头结点  不存放有效数据pNode pHead = (pNode)malloc(sizeof(Node));if (NULL == pHead) {printf("内存分配失败");//程序退出exit(-1);}pNode pTail = pHead;    //pTail也指向了头结点pTail->pNext = NULL;printf("请输入你要输入节点的个数 len =");scanf_s("%d", &len);//假设输入的长度5,我们需要循环for ( i = 0; i < len; i++){printf("请输入第%d个节点的值:", i + 1);scanf_s("%d", &val);pNode pNew=(pNode)malloc(sizeof(Node));if (NULL == pNew) {printf("内存分配失败");//程序退出exit(-1);}pNew->data = val;//pHead->pNext = pNew;//pNew->pNext = NULL;pTail->pNext = pNew;  //将这个新节点挂到尾节点pNew->pNext = NULL;pTail = pNew;}return pHead;
}//遍历
void traverse_list(pNode  pHead) {pNode p = pHead->pNext;while (p!=NULL){printf("%d ",p->data);p = p->pNext;}//换行printf("\n");return;
}//判断链表是否为空
bool is_empty(pNode pHead) {if (NULL == pHead->pNext) {return true;}else {return false;}
}//求一个链表的长度
int length_list(pNode pHead) {pNode p=pHead->pNext;   //第一个节点int len = 0;while (NULL != p) {   //只要指针指向的下一个元素不是空,指针就继续向后移动++len;p=p->pNext;}return len;
} 
算法:
 狭义的算法是与数据的存数方式密切相关
 广义的算法是与数据的存储方式无关
 泛型:
 利用某种技术达到的效果就是:不同的存数方式,执行的操作是一样的