归纳编程学习的感悟,
记录奋斗路上的点滴,
希望能帮到一样刻苦的你!
如有不足欢迎指正!
共同学习交流!
🌎欢迎各位→点赞 👍+ 收藏⭐ + 留言📝
每一个裂缝都是为透出光而努力!
CLinkList.h
#pragma once
#include<stdio.h>
#include<malloc.h>#define DataType inttypedef struct CLNode
{DataType data;struct CLNode* next;
}CLNode,*CLinkList;void InitCLinkList(CLinkList* head);int InsertElem(CLinkList head, int i, DataType e);int DeleteElem(CLinkList head, int i, DataType* e);void InsertElemR(CLinkList head, DataType e);void InsertElemF(CLinkList head, DataType e);
CLinkList.cpp
#include "CLinkList.h"#define _CRT_SECURE_NO_WARNINGS 1void InitCLinkList(CLinkList* head)
{(*head) = (CLinkList)malloc(sizeof(CLNode));(*head)->next = *head;
}int InsertElem(CLinkList head, int i, DataType e)
{CLNode* pre, * p;if (i <= 0){printf("插入位置错误!\n");return -1;}int j;pre = head;j = 0;while (pre->next != head && j < i - 1){pre = pre->next;j++;}if (j != i - 1){printf("插入位置错误!\n");return 0;}p = (CLNode*)malloc(sizeof(CLNode));p->data = e;p->next = pre->next;pre->next = p;return 1;
}int DeleteElem(CLinkList head, int i, DataType* e)
{CLNode* pre, *p;int j;if (i <= 0){printf("删除位置错误!\n");return -1;}pre = head;j = 0;while (pre->next!= head &&j < i - 1){pre = pre->next;j++;}if (j != i - 1){printf("删除位置错误!\n");return 0;}p = pre->next;*e = p->data;pre->next = p->next;free(p);return 1;
}void InsertElemR(CLinkList head, DataType e)
{CLNode* pre, * p;pre = head;while (pre->next != head){pre = pre->next;}p = (CLNode*)malloc(sizeof(CLNode));p->data = e;p->next = pre->next;pre->next = p;
}void InsertElemF(CLinkList head, DataType e)
{CLNode* p;p = (CLNode*)malloc(sizeof(CLNode));p->data = e;p->next = head->next;head->next = p;
}