算法竞赛阶段二-数据结构(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;

}

相关推荐
复杂网络2 小时前
多个 Claude Code 与多个 Codex 协同工作:设计与实现方案
算法
apocelipes16 小时前
常用编程语言和库的正则表达式性能对比
c语言·c++·python·性能优化·golang·开发工具和环境
HjhIron18 小时前
面试常客:字符串算法从入门到进阶
算法·面试
吴佳浩19 小时前
DeepSeek DSpark:Confidence-Scheduled Speculative Decoding 技术解析
人工智能·算法·deepseek
触底反弹21 小时前
🧠 搞懂 Token,才算真正入门大模型——从分词原理到 Embedding 语义实战
javascript·人工智能·算法
vivo互联网技术1 天前
ICLR 2026 | 基于后验采样的图像恢复方法LearnIR:人脸去阴影、去雾
人工智能·算法·aigc
浮生望1 天前
JS字符串与回文算法:从包装类到双指针的面试进阶之路
javascript·算法
黄敬峰1 天前
面试必刷:从JS底层包装类到双指针,彻底搞懂字符串与回文算法
算法
地平线开发者2 天前
J6B vio scenario sample
算法