没有合适的资源?快使用搜索试试~ 我知道了~
C封装双向循环链表对象1
需积分: 0 0 下载量 23 浏览量
2022-08-04
11:27:24
上传
评论
收藏 556KB PDF 举报
温馨提示
试读
14页
1. DoubleCircularLinkedList(双向循环链表) 2. DoubleCircularLinkedList.c文件 3. DoubleCir
资源详情
资源评论
资源推荐
Aug 29, 2018 | 学习笔记——C数据结构 | 3 阅读 | 1.9k 字 | 11 分钟
文章目录
1. DoubleCircularLinkedList(双向循环链表)
2. DoubleCircularLinkedList.c文件
3. DoubleCircularLinkedList.h文件
4. testDoubleCircularLinkedList.c文件
5. 编译:
C封装双向循环链表对象
DoubleCircularLinkedList(双向循环链表)
github源码
特点:
1.插入一个结点temp
p->next->prior = temp;
temp->prior = p;
temp->next = p->next;
p->next = temp;
2.删除一个结点n,时间复杂度O(1)
n->prior->next = n->next;
n->next->prior = n->prior;
free(n);
Mr Bluyee's Blog
首页 归档 关于
3.在末尾增加一个结点temp
temp->elem = *e;
temp->prior = p;
temp->next = head;
p->next = temp;
head->prior = temp;
4.getPriorNode、getNextNode的时间复杂度均为O(1)
static Node *getPriorNode(Node *n){
return n->prior;
}
static Node *getNextNode(Node *n){
return n->next;
}
DoubleCircularLinkedList.c文件
#include <stdio.h>
#include <malloc.h>
#include "DoubleCircularLinkedList.h"
static void clear(DoubleCircularLinkedList *This);
static int isEmpty(DoubleCircularLinkedList *This);
static int length(DoubleCircularLinkedList *This);
static void print(DoubleCircularLinkedList *This);
static void circlePrint(DoubleCircularLinkedList *This,int times);
static int indexElem(DoubleCircularLinkedList *This, ElemType* x);
static int indexNode(DoubleCircularLinkedList *This, Node* n);
static int getElem(DoubleCircularLinkedList *This, int index, ElemType *e);
static Node *getNode(DoubleCircularLinkedList *This, int index);
static Node *getPriorNode(Node *n);
static Node *getNextNode(Node *n);
static int modifyElem(DoubleCircularLinkedList *This, int index, ElemType* e);
static int modifyElem(DoubleCircularLinkedList *This, int index, ElemType* e);
static int deleteElem(DoubleCircularLinkedList *This, int index, ElemType* e);
static int deleteNode(DoubleCircularLinkedList *This, Node* n);
static int appendElem(DoubleCircularLinkedList *This, ElemType *e);
static int insertElem(DoubleCircularLinkedList *This, int index, ElemType *e);
static int popElem(DoubleCircularLinkedList *This, ElemType* e);
DoubleCircularLinkedList *InitDoubleCircularLinkedList(){
DoubleCircularLinkedList *L = (DoubleCircularLinkedList *)malloc(sizeof(DoubleCircularLinkedList));
Node *p = (Node *)malloc(sizeof(Node));
L->This = p;
p->prior = p;
p->next = p;
L->clear = clear;
L->isEmpty = isEmpty;
L->length = length;
L->print = print;
L->circlePrint = circlePrint;
L->indexElem = indexElem;
L->indexNode = indexNode;
L->getElem = getElem;
L->getNode = getNode;
L->getPriorNode = getPriorNode;
L->getNextNode = getNextNode;
L->modifyElem = modifyElem;
L->deleteElem = deleteElem;
L->deleteNode = deleteNode;
L->appendElem = appendElem;
L->insertElem = insertElem;
L->popElem = popElem;
return L;
}
void DestroyDoubleCircularLinkedList(DoubleCircularLinkedList *L){
L->clear(L);
free(L->This);
free(L);
L = NULL;
}
static void clear(DoubleCircularLinkedList *This){
Node *head = This->This;
Node *p = This->This->next;
Node *temp = NULL;
剩余13页未读,继续阅读
不能汉字字母b
- 粉丝: 13
- 资源: 291
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0