用C语言封装的链表的方法 |
|
www.nanhushi.com 佚名 不详 |
#include <stdio.h> #include <stdlib.h> #define TRUE 1 #define ERROR 0 #define BOOL int typedef struct LNode ...{ int data; LNode *next; }LNode,*Linklist; BOOL HeadNOde(Linklist* Head,Linklist* L,int temp) ...{ *Head = (Linklist )malloc(sizeof(LNode)); *L = (Linklist )malloc(sizeof(LNode)); if((!*Head)||(!*L)) ...{ return ERROR; } (*Head)->next = *L; (*L)->data = temp; (*L)->next = NULL; return TRUE; } BOOL InsertList(Linklist* L,int temp) ...{
Linklist L1 = (Linklist )malloc(sizeof(LNode)); if(!L1) ...{ return ERROR; } L1->data = temp; L1->next = *L; *L=L1; return TRUE; } int main() ...{ Linklist Head,List; int temp = 10; HeadNOde(&Head,&List,temp); for(int i=0;i<10;i++) ...{ InsertList(&List,i); } Linklist pList; pList = List; while(pList) ...{ printf("%d ",pList->data); pList = pList->next; }
return 0; }
|
|
|
文章录入:杜斌 责任编辑:杜斌 |
|
上一篇文章: miranda中Service与Event机制分析其结果 下一篇文章: 灵活使用GOTO语句 |
【字体:小 大】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 |
|
|