/*
* 带头结点的单链表相关操作
* */
#include <stdio.h>
#include <stdlib.h>
typedef struct node {
int iData;
struct node *pNext;
}NODE_t;
NODE_t * CreateEmptySList() {
NODE_t *pHead = (NODE_t *)malloc(sizeof(NODE_t));
if (pHead == NULL) {
printf("malloc head node error\n");
return NULL;
}
return pHead;
}
NODE_t * CreateArraySList(int aArray[], int iCnt) {
NODE_t *pHead = CreateEmptySList();
if (pHead == NULL) {
printf("CreateEmptySList error\n");
return NULL;
}
int iIdx = 0;
NODE_t *pNode = NULL;
NODE_t *pCur = pHead;
for (iIdx = 0; iIdx < iCnt; iIdx++) {
pNode = (NODE_t *)malloc(sizeof(NODE_t));
if (pNode == NULL) {
printf("malloc node error\n");
/* 此处应该释放所有申请成功的结点,包括头结点 */
return NULL;
}
pNode->
一:单链表的创建、打印和释放
最新推荐文章于 2024-04-22 19:28:38 发布