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

快速网站建设旅游电子商务网站策划书

快速网站建设,旅游电子商务网站策划书,化妆品的网站布局设计图片大全,秦皇岛建筑前言 大家好,我是Maybe。最近在学习数据结构中的链表,自己手动实现了一个LinkedList。我想与大家分享一下。 思维导图 代码部分 package Constant;public class constant {public static final String INDEX_IS_WRONG"输入的下标不合法"; }p…

前言

大家好,我是Maybe。最近在学习数据结构中的链表,自己手动实现了一个LinkedList。我想与大家分享一下。

思维导图

代码部分

package Constant;public class constant {public static final String INDEX_IS_WRONG="输入的下标不合法";
}
package utils;public class IndexException extends RuntimeException{public IndexException() {super();}public IndexException(String message) {super(message);}
}
public interface IList {// 头插法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();
}
import Constant.constant;
import utils.IndexException;public class LinkedList implements IList {//1.定义一个内部类static class ListNode{public int val;//类型写成了String,应该是ListNode的public ListNode prev;public ListNode next;public ListNode(int val) {this.val = val;}}public ListNode head;//这个就要给个尾了public ListNode last;@Overridepublic void addFirst(int data) {if(head==null){ListNode node=new ListNode(data);head=last=node;}else{ListNode node=new ListNode(data);node.next=head;head.prev=node;head=node;}}@Overridepublic void addLast(int data) {if(head==null){ListNode node=new ListNode(data);//写成了node=last=null了head=last=node;}else{ListNode node=new ListNode(data);last.next=node;node.prev=last;//这里要注意last=last.next;}}@Override//在LinkedList中找到对应的cur,然后再cur之前插入public void addIndex(int index, int data) {int len=size();if(index<0||index>len){String msg= constant.INDEX_IS_WRONG+index;throw new IndexException(msg);}if(index==0){addFirst(data);}else if(index==len){addLast(data);}else{ListNode node=new ListNode(data);ListNode cur=findIndex(index);node.next=cur;cur.prev.next=node;node.prev=cur.prev;cur.prev=node;}}//在LinkedList中找到对应的curprivate ListNode findIndex(int index){if(head==null){return null;}else{ListNode cur=head;while(index!=0){cur=cur.next;index--;}return cur;}}@Overridepublic boolean contains(int key) {if(head==null){return false;}else{ListNode cur=head;while(cur!=null){if(cur.val==key){return true;}else{cur=cur.next;}}return false;}}@Overridepublic void remove(int key) {//1.先判断链表是否为空if(head==null){return;}else{ListNode cur=head;while(cur!=null){if(cur.val==key){//1.考虑头删的情况if(cur==head){head=head.next;//考虑如果链表中只有一个节点的情况if(head!=null){head.prev=null;}}else{cur.prev.next=cur.next;//尾巴节点和中间节点共用if(cur.next==null){//尾节点last=last.prev;}else{//中间节点cur.next.prev=cur.prev;}}return;}cur=cur.next;}}}@Overridepublic void removeAllKey(int key) {if(head==null){return;}else{ListNode cur=head;while(cur!=null){if(cur.val==key){if(cur==head){head=head.next;//只有一个节点的情况要考虑if(head!=null){head.prev=null;}}else{cur.prev.next=cur.next;if(cur.next==null){last=last.next;}else{cur.next.prev=cur.prev;}}}cur=cur.next;}}}@Overridepublic int size() {if(head==null){return 0;}else{ListNode cur=head;int count=0;while(cur!=null){cur=cur.next;count++;}return count;}}@Overridepublic void display() {if(head==null){return;}else{ListNode cur=head;while(cur!=null){System.out.print(cur.val+" ");cur=cur.next;}System.out.println();}}@Overridepublic void clear() {if(head==null){return;}else{ListNode cur=head;while(cur!=null){ListNode curN=cur.next;cur.prev=null;cur.next=null;cur=curN;}head=last=null;//最后要把head和last置为null}}
}
import utils.IndexException;public class Test {public static void main(String[] args) {LinkedList linkedList=new LinkedList();linkedList.addLast(1);linkedList.addLast(1);linkedList.addLast(1);linkedList.addLast(2);linkedList.display();
//        linkedList.addFirst(1);
//        linkedList.addFirst(2);
//        linkedList.addFirst(3);
//        linkedList.addFirst(4);
//        linkedList.display();
//        int ret=linkedList.size();
//        System.out.println(ret);
//        try{
//            linkedList.addIndex(2,100);
//
//        }catch (IndexException e){
//            e.printStackTrace();
//        }
//        linkedList.display();
//        linkedList.remove(1);
//        linkedList.display();
//        linkedList.removeAllKey(1);linkedList.clear();linkedList.display();}
}

结语 

本次分享到此结束啦。希望可以帮到有需要的人!

 

 

 

 

 

 


文章转载自:

http://WZGAVVjr.xhrws.cn
http://LJs2og0M.xhrws.cn
http://L9NLYqvT.xhrws.cn
http://iHnGfpBz.xhrws.cn
http://znFOFcce.xhrws.cn
http://XvZndmbf.xhrws.cn
http://DDRLMEyG.xhrws.cn
http://hBS3MRuM.xhrws.cn
http://uJlLdMIT.xhrws.cn
http://wx6Sxu1v.xhrws.cn
http://7YXTuYVV.xhrws.cn
http://hp4CC2f9.xhrws.cn
http://CTWg7t0Y.xhrws.cn
http://xIFHMOnF.xhrws.cn
http://cG09Du3x.xhrws.cn
http://X9kEbYny.xhrws.cn
http://dDVrHd0C.xhrws.cn
http://LsihWD5E.xhrws.cn
http://oF7YVeL3.xhrws.cn
http://ocY9WUIZ.xhrws.cn
http://LXBjPNzr.xhrws.cn
http://20Gn4FhT.xhrws.cn
http://l47s5kNb.xhrws.cn
http://RqMT8SAG.xhrws.cn
http://3UMTxRlS.xhrws.cn
http://W3xk3bFT.xhrws.cn
http://RBzlH2jA.xhrws.cn
http://TAVD6zhc.xhrws.cn
http://LG5k9wfd.xhrws.cn
http://X037KZ7b.xhrws.cn
http://www.dtcms.com/wzjs/751830.html

相关文章:

  • 提供网站建设设计公司排名公司网站后台维护怎么做
  • 制作网站的收获体会网站备案 的类型
  • 电商网站前端架构设计厦门有家装饰
  • 工程招聘网站延安网站建设报价
  • 潍坊市安丘建设局网站宁波网站建设工作室
  • 长沙做网站最好的公司有哪些外卖网站建设可行性分析
  • 无锡游戏网站建设公司wordpress免费 主题
  • 嘉兴网站如何制作wordpress 搭建app
  • 网站设计师专业邯郸网络安装
  • 太平阳电脑网网站模板小程序开发需要多少钱?
  • 网站建设信息平台买域名不建网站
  • 九江本土专业网站建设免费免费网站模板
  • 外贸网站如何推广出去泉州全网营销优化
  • 网站建设企公司app与网站建设方案
  • 站长网网站模板中山大兴网站建设
  • 网站建设具备什么条件福建建设中心网站
  • 淄川响应式网站建设企业网站的结构以及内容.
  • 淘宝客网站要多大空间网站做兼容处理怎么设置
  • 用什么软件做购物网站做定制网站怎么样
  • 做网站公司排行网站开发的有关公司
  • 可以看网站的手机浏览器珠海微信网站开发
  • 腾讯做网站上传wordpress二级菜单代码
  • 网站建设费用上海北京市建筑网站
  • 护肤品网站建设需求分析企业宣传册模板
  • 磁力搜索网站怎么做的国外设计素材app
  • wordpress福利整站源码郑州安卓app开发
  • 行政机关网站建设关于集团官方网站内容建设的报告
  • 西部网站邮箱登录城乡建设部官方网站
  • 网站策划专员怎么做家庭网站
  • 最近几年做电影网站怎么样微信网页制作的软件