标签:单链表
typedef struct LNode { int data; struct LNode *next; } LNode; void CreateF(LNode *&L, int n) //头插法创建链表 { int i; LNode *p; L = (LNode *)malloc(sizeof(LNode)); L->next = NULL; for(i = 1; i <= n; ++i) { p = (LNode *)malloc(sizeof(LNode)); p->next = NULL; scanf("%d", &p->data); p->next = L->next; L->next = p; } } void CreateR(LNode *&L, int n) //尾插法创建链表 { int i; LNode *p, *s; L = (LNode *)malloc(sizeof(LNode)); L->next = NULL; p = L; for(i = 1; i <= n; ++i) { s = (LNode *)malloc(sizeof(LNode)); s->next = NULL; scanf("%d", &s->data); p->next = s; p = s; } } void ReverseL(LNode *L) //链表反转 { if(L->next == NULL) return ; LNode *p, *q; p = L->next; while(p->next != NULL) { q = p->next; p->next = q->next; q->next = L->next; L->next = q; } } void PrintL(LNode *L) //打印链表 { LNode *p = L->next; while(p != NULL) { printf("%d ", p->data); p = p->next; } printf("\n"); } void DestroyL(LNode *&L) //销毁链表 { LNode *p; while(L != NULL) { p = L->next; free(L); L = p; } }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:单链表
原文地址:http://blog.csdn.net/lyhvoyage/article/details/47359909