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

asp动态网站开发教程seo优化公司哪家好

asp动态网站开发教程,seo优化公司哪家好,wordpress的页面,做网页培训目录 整体框架IMyLinkedList接口IndexNotLegalException异常类MyLinkedList类成员变量(节点信息)addFirst(头插)addLast(尾插)在指定位置插入数据判断是否存在移除第一个相等的节点移除所有相等的节点链表的长度打印链表释放回收链表 整体框架 IMyLinkedList接口 这个接口用来…

目录

  • 整体框架
  • IMyLinkedList接口
  • IndexNotLegalException异常类
  • MyLinkedList类
    • 成员变量(节点信息)
    • addFirst(头插)
    • addLast(尾插)
    • 在指定位置插入数据
    • 判断是否存在
    • 移除第一个相等的节点
    • 移除所有相等的节点
    • 链表的长度
    • 打印链表
    • 释放回收链表

整体框架

在这里插入图片描述

IMyLinkedList接口

这个接口用来存放所有方法,之后用MyLinkedList来实现这个接口,重写里面的方法

public interface IMyLinkedList {//头插法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 display();//释放链表public void clear();
}

IndexNotLegalException异常类

IndexNotLegalExceprion异常类用来判断index是否合法

public class IndexNotLegalException extends RuntimeException{public IndexNotLegalException() {}public IndexNotLegalException(String msg) {super(msg);}
}

MyLinkedList类

成员变量(节点信息)

static class ListNode {public int val;public ListNode prev;public ListNode next;public ListNode (int val){this.val = val;}}public ListNode head;public ListNode last;

addFirst(头插)

public void addFirst(int data) {ListNode newNode = new ListNode(data);if(head == null){head = last = newNode;}else{newNode.next = head;head.prev = newNode;head = newNode;}}

addLast(尾插)

public void addLast(int data) {ListNode newNode = new ListNode(data);if(head == null){head = last = newNode;}else{newNode.prev = last;last.next = newNode;last = newNode;}}

在指定位置插入数据

public void addIndex(int index, int data) {//判断index的合法性try{checkIndex(index);}catch(IndexNotLegalException e){e.printStackTrace();}if(index == 0){addFirst(data);return;}if(index == size()){addLast(data);return;}ListNode newNode = new ListNode(data);ListNode cur = head;while(index != 0){cur = cur.next;index--;}newNode.next = cur;newNode.prev = cur.prev;cur.prev.next = newNode;cur.prev = newNode;}private void checkIndex(int index){if(index<0 || index>size()){throw new IndexNotLegalException("Index不合法...");}}

判断是否存在

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

移除第一个相等的节点

public void remove(int key) {ListNode cur = head;if(head.val == key && head == last){head = last = null;return;}//如果删除的在head节点if(head.val == key){head = head.next;head.prev = null;return;}while(cur != null){if(cur.val == key){cur.prev.next = cur.next;if(cur.next == null){last = cur.prev;break;}cur.next.prev = cur.prev;}cur = cur.next;}}

移除所有相等的节点

public void removeAllKey(int key) {ListNode cur = head;if(head.val == key && head == last){head = last = null;return;}//如果删除的在head节点if(head.val == key){head = head.next;head.prev = null;}while(cur != null){if(cur.val == key){cur.prev.next = cur.next;if(cur.next == null){last = cur.prev;break;}cur.next.prev = cur.prev;}cur = cur.next;}}

链表的长度

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

打印链表

    public void display() {ListNode cur = head;while (cur != null) {System.out.print(cur.val + " ");cur = cur.next;}System.out.println();}

释放回收链表

public void clear() {ListNode cur = head;while(cur != null){ListNode curN = cur.next;cur.prev = null;cur.next = null;cur = curN;}}
http://www.hkea.cn/news/192848/

相关文章:

  • 天津网站设计成功柚米全网推广成功再收费
  • 建设公司网站靠谱吗企业网站设计制作
  • 电子商务学什么课程内容兰州搜索引擎优化
  • 沧州网站建设制作设计优化能打开的a站
  • 石家庄网站建设推广报价怎么让百度快速收录网站
  • 建设局网站上开工日期选不了制作网站需要多少费用
  • 犬舍网站怎么做网页推广怎么做
  • 镇江核酸检测最新通知如何优化网页加载速度
  • wpf入可以做网站吗竞价托管外包费用
  • 公司设计网站需要包含什么资料优化排名软件
  • 日本樱花云服务器wan亚马逊seo关键词优化软件
  • layui框架的wordpress厦门站长优化工具
  • 微网站设计尺寸培训课程总结
  • 保险平台官网湖北搜索引擎优化
  • 西安微信小程序制作公司关键词优化方法
  • 手机网站建设用乐云seo搜索引擎是什么意思啊
  • 昆明做大的网站开发公司google网页搜索
  • 做网站运营需要什么证宁波靠谱营销型网站建设
  • 天津进口网站建设电话青岛网站建设公司
  • 游戏币网站建设win7优化大师官方网站
  • 技术专业网站建设班级优化大师网页版登录
  • 外国网站上做雅思考试台州百度推广优化
  • 男女做那种的的视频网站国内最好的搜索引擎
  • 泉州做网站优化价格成功品牌策划案例
  • 做网站去哪个平台资源优化排名网站
  • 备案的网站名称可以改吗百度青岛代理公司
  • 专做进口批发的网站关键词优化多少钱
  • 做网站有了空间在备案吗百度权重高的网站有哪些
  • 做空间的网站著名的网络营销案例
  • 做网站客户尾款老不给怎么办百度推广年费多少钱