算法竞赛阶段二-数据结构(36)数据结构双向链表模拟实现

//#include<bits/stdc++.h>

#include<iostream>

using namespace std;

const int N=1e5+10;

//定义

int eN,preN,neN,h,id;

int mpN;

//头插

// 兵 y

// x

void push_front (int x)

{

id++;

eid=x;

mpx=id;

preid=h;

neid=neh;

//先修改新节点

// prene\[id]=id; ne【id】就是ne【h】看上边,刚赋的值

prene\[h]=id;

// preid=h;

neh=id; //最后改这个

}

// 遍历打印,无视pre即可

void print()

{

for(int i=neh;i;i=nei)

{

cout<<ei<<" ";

}cout<<endl;

}

// 按值查找,mp数组优化·

int find(int x)

{

return (mpx);

}

// 任意位置(存储位置,下标)之后插入

// p

// 1 3

// x

void insert(int p,int x)

{

id++;

eid=x;

mpx=id;

preid=p;

neid=nep;

// preid=p;

prene\[p]=id;

nep=id;

}

//任意位置(存储位置,下标)之前插入

// p

// 1 2

// x

void insret_front(int p,int x)

{

id++;

eid=x;

mpx=id;

neid=p;

preid=prep;

nepre\[p]=id;

prep=id;

}

//删除任意位置元素

// p

// 1 2

// x

void erase(int p)

{

// mpp=0; 这个不对

mpe\[p]=0;

nepre\[p]=nep;

prene\[p]=prep;

}

int main()

{

for(int i=0;i<6;i++)

{

push_front(i);

}

print();

cout<< find(0)<<endl;

cout<< find(2)<<endl;

insert(1,33);

print();

insert(7,88);

print();

cout<< find(33)<<endl;

cout<< find(88)<<endl;

insret_front(1,66);

print();

insret_front(3,33);

print();

insret_front(8,100);

print();

insret_front(9,666);

print();

erase(1);

print();

cout<< find(100)<<endl;

erase(11);

print();

erase(7);

print();

erase(find(666));

print();

return 0;

}

相关推荐
何以解忧,唯有..几秒前
预订酒店问题
算法
JavaPub-rodert3 分钟前
我把 OpenAI 协议塞进了 Go 工具库:go-commons 开始支持 AI 了
开发语言·人工智能·golang
caimouse3 分钟前
ReactOS 图形系统分析(23):引擎内存管理 — mem.c
c语言·开发语言
caimouse3 分钟前
ReactOS 图形系统分析(15):窗口对象 — EWNDOBJ(engwindow.c)
c语言·开发语言
青 春 记 忆7 分钟前
零基础入门python07:让程序记住数据——JSON文件和异常处理
开发语言·windows·python·json·python3.11
No8g攻城狮9 分钟前
【算法】什么是 DFS 与 BFS 及他们的区别
算法·深度优先·宽度优先
举手13 分钟前
Epoll模型
linux·c++·学习
zww894911117 分钟前
家政派单系统实战指南:从需求分析到智能调度算法落地
算法·需求分析
W_3260028 分钟前
Python 常用标准 / 第三方库:random、tqdm、turtle、jieba 用法
开发语言·python
手写码匠30 分钟前
华为云Flexus+DeepSeek征文|Dify 多 Agent 评测实战:用 DeepSeek-R1 当裁判,打造多智能体系统的自动化质量保障体系
人工智能·深度学习·算法·aigc