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

重庆网站建设外包网络广告营销的概念

重庆网站建设外包,网络广告营销的概念,提供大良网站建设,兰州市城市建设设计院官方网站LinkedList是双向链表结构可以适用于任意插入场景下的插入和删除,效率较高,时间复杂度为O(1)。 模拟实现 public class MyLinkedList {static class ListNode{private int val;//值域private ListNode prev;//前驱private ListNode next;//后继public …

LinkedList是双向链表结构可以适用于任意插入场景下的插入和删除,效率较高,时间复杂度为O(1)。

模拟实现

public class MyLinkedList {static class ListNode{private int val;//值域private ListNode prev;//前驱private ListNode next;//后继public ListNode(int val) {this.val = val;}}public ListNode head;//双向链表的头节点public ListNode last;//双向链表的尾节点
}

LinkedList常用方法

//头插法
public void addFirst(int data)//尾插法
public void addLast(int data)//任意位置插入,第一个数据节点为0号下标
public void addIndex(int index,int data)//查找是否包含关键字key是否在单链表当中
public boolean contains(int key)//删除第一次出现关键字为key的节点
public void remove(int key)//删除所有值为key的节点
public void removeAllKey(int key)//得到链表的长度
public int size()//清空链表
public void clear()

实现addFirst方法(头插法)

public void addFirst(int data){ListNode node = new ListNode(data);//如果链表为空 插入的元素就是头节点和尾节点if (head==null){head = node;last = node;}else {node.next = head;//使node的后继是现在的头节点head.prev = node;//使现在的头节点的前驱是nodehead = node;//让node成为新的头节点}
}

实现addList方法(尾插法)

public void addLast(int data){ListNode node = new ListNode(data);//和头插一样if (last==null){head = node;last = node;}else {last.next = node;//使现在尾节点的后继为nodenode.prev = last;//使node的前驱为现在的尾节点last = last.next;//让node成为尾节点}
}

实现size方法(求链表长度)

public int size(){ListNode cur = head;int count = 0;while (cur!=null){count++;cur = cur.next;}return count;
}

实现addIndex方法(在任意位置插入元素)

public void addIndex(int index,int data){//插入的位置如果为0 可以使用头插法if (index==0){addFirst(data);return;}//如果在最后一个位置插入 可以使用尾插法if (index==size()){addLast(data);return;}ListNode node = new ListNode(data);//判断要插入的下标是否合法if (index<0||index>size()){System.out.println("index 不合法"+index);return;}ListNode cur = head;//让cur走到要插入的位置while (index!=0){cur = cur.next;index--;}node.next = cur;cur.prev.next = node;node.prev = cur.prev;cur.prev = node;
}

实现contains方法(查找是否包含关键字key是否在单链表当中)

public boolean contains(int key){if (head==null){return false;}ListNode cur = head;while (cur!=null){if (cur.val==key){return true;}cur = cur.next;}return false;
}

实现remove方法(删除第一次出现关键字为key的节点)

public void remove(int key){ListNode cur = head;while (cur!=null){if (cur.val==key){//删除头节点if (cur==head){head = head.next;if (head==null){//只有一个头节点cur.prev=null;}else {last=null;}}else {if (cur.next!=null){//删除中间节点cur.prev.next=cur.next;cur.next.prev=cur.prev;}else {//删除尾节点cur.prev.next=cur.next;last=last.prev;}}return;}else {cur=cur.next;}}
}

实现removeAllkey(删除所有值为key的节点)

public void removeAllKey(int key){ListNode cur = head;while (cur!=null){if (cur.val==key){//删除头节点if (cur==head){head = head.next;if (head==null){//只有一个头节点cur.prev=null;}else {last=null;}}else {if (cur.next!=null){//删除中间节点cur.prev.next=cur.next;cur.next.prev=cur.prev;}else {//删除尾节点cur.prev.next=cur.next;last=last.prev;}}cur=cur.next;}else {cur=cur.next;}}
}

实现clear方法(清除链表)

public void clear(){ListNode cur = head;while (cur!=null){ListNode curNew = cur.next;cur.prev=null;cur.next=null;cur = curNew;}head=null;last=null;
}
http://www.dtcms.com/wzjs/462161.html

相关文章:

  • wordpress 引入样式个人如何优化网站有哪些方法
  • b2b2c网站怎么做企业网络营销推广平台
  • 做网站应达到什么效果关键词搜索量查询
  • 电子商务网站的数据库怎么做google怎么推广
  • 朝阳网站建设多少钱影视网站怎么优化关键词排名
  • 杭州网站排名优化360优化大师官方下载最新版
  • wordpress博客优秀南宁百度seo排名
  • 佛山高端网站设计2023年3月份疫情严重
  • 开发公司移交柴油发动机需要具备哪些条件沈阳seo建站
  • 阅读网站建设网络推广方案
  • 怎么在网上做网站公司怎么做网站推广
  • 网站风格包括营销培训心得体会
  • 做网站好平台化目前最新的营销方式有哪些
  • app的制作需要多少钱seo搜索引擎优化排名哪家更专业
  • 大专毕业设计网站公众号怎么推广和引流
  • 奎屯市住房和城乡建设局网站中层管理者培训课程有哪些
  • 如何用c语言做网站win10优化工具
  • 做短视频网站需要审批app投放渠道有哪些
  • 只做正品的网站网站设计公司建设网站
  • 我做网站价格seo排名工具提升流量
  • 360ssp网站代做seo网站推广优化
  • 重庆的企业的网站建设百度推广用户注册
  • 官方网站建设情况海外seo培训
  • 建 导航网站好百度宁波运营中心
  • 做彩票网站需要境外关键词推广和定向推广
  • 怎么开无货源网店赚钱站长工具seo推广
  • 域名备案 没有网站凡科建站网站
  • 做网站包括什么武汉百度推广电话
  • 做网站游戏总结的例文站内推广方案
  • 免费网站开发百度一下首页问问