C语言写一个链表

来源:百度知道 编辑:UC知道 时间:2024/05/04 21:59:35
用C语言写一个链表 写几个函数 实现插入 删除 之类的操作 !
多谢

用连表实现栈的操作:我以前写的代码:
typedef char datetype1;
typedef struct dateare1{
datetype1 elem;
struct dateare1 *forth;
}datestruct1;
typedef struct {
datestruct1 *base,*top;
int length;
}OPTR;
Lstack createOPTR(){
OPTR L;
datestruct1 *p;
p=(datestruct1 *)malloc(sizeof(datestruct1));
if(p)
{L.base=p;
L.top=p;
L.top->forth=NULL;
L.length=0;
return L;}
else {printf("\nINITSTACK ERROR");exit();}
}
void pushOPTR(OPTR *Lsp,datetype1 e) {datestruct1 *p;
p=(datestruct1 *)malloc(sizeof(datestruct1));
if(p)
{ (*Lsp).top->elem=e;
p->forth=(*Lsp).top;
(*Lsp).top=p;
(*Lsp).length++;}
else {printf("\nAPPLY MEMORY ERROR");exit();}
}
datetype1 popOPTR(OPTR *Lsp) {
datestruct1 *p;
p=(*Lsp).top;
i