当前位置: 首页 > news >正文

大连市网站建设_网站建设公司_前后端分离_seo优化

可以做录音兼职的网站,宁波网站建设培训,山东省山东省建设厅网站,广东东莞职业技术学院文章目录1. 设计一个单链表2. 双向链表1. 设计一个单链表 在链表类中实现这些功能#xff1a; get(index)#xff1a;获取链表中第 index 个节点的值。如果索引无效#xff0c;则返回-1。 addAtHead(val)#xff1a;在链表的第一个元素之前添加一个值为 val 的节点。插入… 文章目录1. 设计一个单链表2. 双向链表1. 设计一个单链表 在链表类中实现这些功能 get(index)获取链表中第 index 个节点的值。如果索引无效则返回-1。 addAtHead(val)在链表的第一个元素之前添加一个值为 val 的节点。插入后新节点将成为链表的第一个节点。 addAtTail(val)将值为 val 的节点追加到链表的最后一个元素。 addAtIndex(index,val)在链表中的第 index 个节点之前添加值为 val 的节点。如果 index 等于链表的长度则该节点将附加到链表的末尾。如果 index 大于链表长度则不会插入节点。如果index小于0则在头部插入节点。 deleteAtIndex(index)如果索引 index 有效则删除链表中的第 index 个节点。 来源力扣LeetCode 链接https://leetcode-cn.com/problems/design-linked-list 著作权归领扣网络所有。商业转载请联系官方授权非商业转载请注明出处。 class node { public:int val;node *next;node(int v):val(v),next(NULL) {} }; class MyLinkedList {node *head, *tail;int len; public:/** Initialize your data structure here. */MyLinkedList() {head tail NULL;len 0;}/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */int get(int index) {if(index len || index 0)return -1;node *cur head;while(index--)cur cur-next;return cur-val;}/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */void addAtHead(int val) { node *h new node(val);h-next head;head h;if(len 0)tail head;len;}/** Append a node of value val to the last element of the linked list. */void addAtTail(int val) {node *t new node(val);if(len 0){head tail t;}else{tail-next t;tail t;}len; }/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */void addAtIndex(int index, int val) {if(index len)addAtTail(val);else if(index 0)addAtHead(val);else if(index len)return;else{node *cur head;while(--index)cur cur-next;node *newNode new node(val);newNode-next cur-next;cur-next newNode;len;}}/** Delete the index-th node in the linked list, if the index is valid. */void deleteAtIndex(int index) {if(index len || index 0)return;--len;node *virtualheadNode, *del, *cur;virtualheadNode new node(0);virtualheadNode-next head;cur virtualheadNode;while(index--){cur cur-next;}del cur-next;cur-next cur-next-next;delete del;head virtualheadNode-next;if(cur-next NULL)tail cur;delete virtualheadNode;} };2. 双向链表 class node { public:int val;node *next;node *prev;node(int v):val(v),next(NULL),prev(NULL) {} }; class MyLinkedList {node *head, *tail;int len; public:/** Initialize your data structure here. */MyLinkedList() {head tail NULL;len 0;}/** Get the value of the index-th node in the linked list. If the index is invalid, return -1. */int get(int index) {if(index len || index 0)return -1;node *cur head;while(index--)cur cur-next;return cur-val;}/** Add a node of value val before the first element of the linked list. After the insertion, the new node will be the first node of the linked list. */void addAtHead(int val) { node *h new node(val);h-next head;head h;if(len 0)tail head;len;}/** Append a node of value val to the last element of the linked list. */void addAtTail(int val) {node *t new node(val);if(len 0){head tail t;}else{tail-next t;t-prev tail;tail t;}len; }/** Add a node of value val before the index-th node in the linked list. If index equals to the length of linked list, the node will be appended to the end of linked list. If index is greater than the length, the node will not be inserted. */void addAtIndex(int index, int val) {if(index len)addAtTail(val);else if(index 0)addAtHead(val);else if(index len)return;else{node *cur head;while(--index)cur cur-next;node *newNode new node(val);newNode-next cur-next;newNode-prev cur;cur-next-prev newNode;cur-next newNode;len;}}/** Delete the index-th node in the linked list, if the index is valid. */void deleteAtIndex(int index) {if(index len || index 0)return;--len;node *virtualheadNode, *del, *cur;virtualheadNode new node(0);virtualheadNode-next head;head-prev virtualheadNode;cur virtualheadNode;while(index--){cur cur-next;}del cur-next;cur-next cur-next-next;if(del-next) del-next-prev cur;delete del;head virtualheadNode-next;if(cur-next NULL)tail cur;delete virtualheadNode;} };
http://www.ihoyoo.com/news/75178.html

相关文章:

  • 给传销做网站自媒体平台注册下载
  • 网站建设代码怎么写网络架构师证书怎么考
  • wordpress用户冻结北京网络推广公司wyhseo
  • 一个购物网站开发语言汕头建筑
  • 做网站做生意源码论坛网搭建
  • 做网站用新域名还是老域名网站备案官网
  • 东莞长安做网站广州网站建设交易
  • 网站建设优惠教育网站建设解决方案
  • 注册top域名做公司网站南通seo快速排名
  • 中国中小企业信息网sem跟seo的区别
  • 网站开发当前城市定位功能企业建站公司
  • 电子商务网站后台导航网站制作教程
  • 俄语网站制作艺术视频手机网站可以做吗
  • 建设跳转公积金网站定制网站公司哪家好
  • 济南品质网站建设哪家好wordpress qq登陆插件
  • 成都网站建设 外包高端app定制开发
  • 网站设计网站设计公司价格网络正能量你懂我意思的
  • 郑州网站建设开发网站建设克隆
  • 网站做优化的好处实时新闻
  • 南京住房和城乡建设部网站进入公众号后没有什么显示
  • 建网站公司营销型网站建设餐饮网站建设有什么好处
  • 免费上传图片的网址青岛网站seo收费
  • 欧美网站风格推荐几个免费的网站
  • 网站推广话术与技巧无锡网站制作哪里有
  • 网站数据包括哪些内容上海专业的网络推广
  • 温州市微网站制作多少钱wordpress最新app
  • 永久免费的建站系统有哪些贵阳手机网站制作
  • 鹰潭做网站的公司网站数据查询
  • 云主机安装网站22 wordpress 模板
  • 石家庄心雨网站建设肇庆网站制作