#include//标准函数输出库#include//包含malloc()函数的函数库#defineOK1//宏定义OK为1#defineERROR0//宏定义ERROR为0structNode{intele;structNode*next;};/*顺序表的表示方法*/typedefstruct{structNode*pData;intlength;}LinkedList;/*顺序表的初始化*/LinkedList*InitList(LinkedList*L){if(NULL==L){L=(LinkedList*)malloc(sizeof(LinkedList));//如果链表不存在则开辟空间if(
L){printf("为L申请空间失败
\n");//如果申请失败输出提示语}}L->pData=(structNode*)malloc(sizeof(structNode));//为指针头结点开辟空间if(
L->pData){printf("为L->pData申请空间失败
\n");returnNULL;}else{L->pData->next=NULL;//头结点指向空}L->length=0;//链表长度为0returnL;}/*顺序表的销毁*/intDestroyList(LinkedList*L){-1-intk=1;structNode*p=L->pData->next,*q=L->pData;for(k=1;klength;k++){free(q);//释放指针q所指向的空间q=p;//p指针顺序后移p=q->next;}free(q);//释放最后结点的内存L->pData=NULL;//把链表地址置空return1;}/*向第i个位置插入值为x的元素,在第一个位置插入数据时i为1*/intInsertElem(LinkedList*L,intx,inti)