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

常熟做网站多少钱五行seo博客

常熟做网站多少钱,五行seo博客,建设电子商务网站的好处,全国公共资源交易平台官网文章目录 1.了解什么是顺序表2.实现哪些功能3.初始化ArrayList4.实现功能接口遍历顺序表判断顺序表是否已满添加元素指定下标添加元素自定义下标不合法异常判断顺序表是否为空查找指定元素是否存在查找指定元素返回下标获取指定下标的元素顺序表为空异常修改指定下标元素的值删…

文章目录

  • 1.了解什么是顺序表
  • 2.实现哪些功能
  • 3.初始化ArrayList
  • 4.实现功能接口
    • 遍历顺序表
    • 判断顺序表是否已满
    • 添加元素
    • 指定下标添加元素
    • 自定义下标不合法异常
    • 判断顺序表是否为空
    • 查找指定元素是否存在
    • 查找指定元素返回下标
    • 获取指定下标的元素
    • 顺序表为空异常
    • 修改指定下标元素的值
    • 删除指定元素
    • 顺序表长度
    • 回收顺序表
  • 完整代码

1.了解什么是顺序表

顺序表是用一段物理地址连续的存储单元依次存储数据元素的线性结构,一般情况下采用数组存储。在数组上完成数据的增删查改。

2.实现哪些功能

对于一个顺序表来说
我们做的最多的也就是增删查改
则实现以下接口:

public interface IList {//新增元素,默认在数组最后新增public void add(int data);// 在 pos 位置新增元素public void add(int pos, int data);// 判定是否包含某个元素public boolean contains(int toFind) ;// 查找某个元素对应的位置public int indexOf(int toFind);// 获取 pos 位置的元素public int get(int pos);// 给 pos 位置的元素设为 value  更新public void set(int pos, int value);//删除第一次出现的关键字keypublic void remove(int toRemove) ;// 获取顺序表长度public int size();// 清空顺序表public void clear() ;// 打印顺序表,注意:该方法并不是顺序表中的方法,为了方便看测试结果给出的public void display();//判断是否已满boolean isFull();//判断是否为空public boolean isEmpty();
}

3.初始化ArrayList

usedSize为使用的长度
DEFAULT_SIZE = 10为默认顺序表的容量
两个构造方法
无参构造:顺序表默认大小为10;
有参构造:自定义顺序表大小;

public class MyList implements IList{public int[] elem ;public int usedSize;//0//顺序表的 默认大小public static final int DEFAULT_SIZE = 10;public MyList(){this.elem = new int[DEFAULT_SIZE];}public MyList(int capacity){this.elem = new int[capacity];}}

4.实现功能接口

遍历顺序表

public void display(){for (int i = 0; i < usedSize; i++) {System.out.print(elem[i]+" ");}System.out.println();}

判断顺序表是否已满

public boolean isFull(){return usedSize == elem.length;}

添加元素

checkCapacity()判断顺序表是否已满,如果已经满了则进行扩容
扩容为原来顺序表的两倍

 private void checkCapacity(){if(isFull()){elem = Arrays.copyOf(elem,elem.length*2);}}public void add(int data){checkCapacity();elem[this.usedSize] = data;this.usedSize++;}

指定下标添加元素

checkPosOnAdd()判断下标是否合法,如果不合法抛出异常

public void checkPosOnAdd(int pos) throws PosIllegality{if(pos < 0 || pos >usedSize){System.out.println("不合法!");throw new PosIllegality("获取指定下标的元素异常: "+pos);}}public void add(int pos, int data){try{checkPosOnAdd(pos);}catch (PosIllegality e){e.printStackTrace();return;}checkCapacity();for (int i = usedSize-1; i >= pos; i--) {elem[i+1] = elem[i];}elem[pos] = data;usedSize++;}

自定义下标不合法异常

package mylist;public class PosIllegality extends RuntimeException{public PosIllegality(String msg){super(msg);}
}

判断顺序表是否为空

public boolean isEmpty(){return usedSize == 0;}

查找指定元素是否存在

  public boolean contains(int toFind){if(isEmpty()){return false;}for (int i = 0; i < usedSize; i++) {if(elem[i] == toFind){return true;}}return false;}

查找指定元素返回下标

 public int indexOf(int toFind){if(isEmpty()){return -1;}for (int i = 0; i < usedSize; i++) {if(elem[i] == toFind){return i;}}return -1;}

获取指定下标的元素

public void checkPosOnGetAndSet(int pos) throws PosIllegality {if(pos < 0 || pos >= usedSize){System.out.println("不合法");throw new PosIllegality("获取指定下标的元素异常: "+pos);}}public int get(int pos) throws MyArrayListEmpty{checkPosOnGetAndSet(pos);if(isEmpty()){throw new MyArrayListEmpty("获取指定下标元素时" +"顺序表为空!");}return elem[pos];}

顺序表为空异常

package mylist;public class MyArrayListEmpty extends RuntimeException{public MyArrayListEmpty(String msg){super(msg);}
}

修改指定下标元素的值

public void set(int pos, int value){checkPosOnGetAndSet(pos);elem[pos] = value;}

删除指定元素

  public void remove(int toRemove){int index = indexOf(toRemove);if(index == -1){System.out.println("没有找到");return;}for (int i = index; i < usedSize - 1; i++) {elem[i] =elem[i+1];}usedSize--;}

顺序表长度

  public int size(){return this.usedSize;}

回收顺序表

 public void clear() {usedSize = 0;}

完整代码

在这里插入图片描述

package mylist;import java.util.Arrays;public class MyList implements IList{public int[] elem ;public int usedSize;//0//顺序表的 默认大小public static final int DEFAULT_SIZE = 10;public MyList(){this.elem = new int[DEFAULT_SIZE];}public MyList(int capacity){this.elem = new int[capacity];}public void display(){for (int i = 0; i < usedSize; i++) {System.out.print(elem[i]+" ");}System.out.println();}public boolean isFull(){return usedSize == elem.length;}private void checkCapacity(){if(isFull()){elem = Arrays.copyOf(elem,elem.length*2);}}public void add(int data){checkCapacity();elem[this.usedSize] = data;this.usedSize++;}public void checkPosOnAdd(int pos) throws PosIllegality{if(pos < 0 || pos >usedSize){System.out.println("不合法!");throw new PosIllegality("获取指定下标的元素异常: "+pos);}}public void add(int pos, int data){try{checkPosOnAdd(pos);}catch (PosIllegality e){e.printStackTrace();return;}checkCapacity();for (int i = usedSize-1; i >= pos; i--) {elem[i+1] = elem[i];}elem[pos] = data;usedSize++;}public boolean isEmpty(){return usedSize == 0;}public boolean contains(int toFind){if(isEmpty()){return false;}for (int i = 0; i < usedSize; i++) {if(elem[i] == toFind){return true;}}return false;}public int indexOf(int toFind){if(isEmpty()){return -1;}for (int i = 0; i < usedSize; i++) {if(elem[i] == toFind){return i;}}return -1;}public void checkPosOnGetAndSet(int pos) throws PosIllegality {if(pos < 0 || pos >= usedSize){System.out.println("不合法");throw new PosIllegality("获取指定下标的元素异常: "+pos);}}public int get(int pos) throws MyArrayListEmpty{checkPosOnGetAndSet(pos);if(isEmpty()){throw new MyArrayListEmpty("获取指定下标元素时" +"顺序表为空!");}return elem[pos];}public void set(int pos, int value){checkPosOnGetAndSet(pos);elem[pos] = value;}public void remove(int toRemove){int index = indexOf(toRemove);if(index == -1){System.out.println("没有找到");return;}for (int i = index; i < usedSize - 1; i++) {elem[i] =elem[i+1];}usedSize--;}public int size(){return this.usedSize;}public void clear() {usedSize = 0;}
}

文章转载自:
http://dinncoventilation.tqpr.cn
http://dinncourbia.tqpr.cn
http://dinncorose.tqpr.cn
http://dinncoastacin.tqpr.cn
http://dinncochelated.tqpr.cn
http://dinncostammrel.tqpr.cn
http://dinncodominee.tqpr.cn
http://dinncoinversive.tqpr.cn
http://dinncopodzolization.tqpr.cn
http://dinncorustproof.tqpr.cn
http://dinncoiraser.tqpr.cn
http://dinncofatigable.tqpr.cn
http://dinncodeformation.tqpr.cn
http://dinncora.tqpr.cn
http://dinncochamberlaine.tqpr.cn
http://dinncotemplate.tqpr.cn
http://dinncoactinic.tqpr.cn
http://dinncopremune.tqpr.cn
http://dinncounwakened.tqpr.cn
http://dinncoulminic.tqpr.cn
http://dinncobarrater.tqpr.cn
http://dinncolexicalize.tqpr.cn
http://dinncopancreatin.tqpr.cn
http://dinncoscholiast.tqpr.cn
http://dinncoantarctic.tqpr.cn
http://dinncodilatation.tqpr.cn
http://dinncofallacy.tqpr.cn
http://dinncotorpedoman.tqpr.cn
http://dinncowindpipe.tqpr.cn
http://dinncobetel.tqpr.cn
http://dinncomasterly.tqpr.cn
http://dinncoforedoom.tqpr.cn
http://dinncoperdu.tqpr.cn
http://dinncogoldstar.tqpr.cn
http://dinncotasses.tqpr.cn
http://dinncoforensics.tqpr.cn
http://dinncohebraist.tqpr.cn
http://dinncozincification.tqpr.cn
http://dinncosenopia.tqpr.cn
http://dinncoallometry.tqpr.cn
http://dinncorhizoplane.tqpr.cn
http://dinncoradiochemical.tqpr.cn
http://dinncoaccumulate.tqpr.cn
http://dinncocokery.tqpr.cn
http://dinncolighter.tqpr.cn
http://dinncocontrolling.tqpr.cn
http://dinncorhetorically.tqpr.cn
http://dinncobayern.tqpr.cn
http://dinncodarktown.tqpr.cn
http://dinncoworcestershire.tqpr.cn
http://dinncothiomersal.tqpr.cn
http://dinncopreformation.tqpr.cn
http://dinncozorana.tqpr.cn
http://dinncobaps.tqpr.cn
http://dinncopathobiology.tqpr.cn
http://dinncosupinely.tqpr.cn
http://dinncodoldrums.tqpr.cn
http://dinncojindyworobak.tqpr.cn
http://dinncomucociliary.tqpr.cn
http://dinncotidiness.tqpr.cn
http://dinncocomplementizer.tqpr.cn
http://dinncofloccule.tqpr.cn
http://dinncobloomy.tqpr.cn
http://dinncobdst.tqpr.cn
http://dinncoastringently.tqpr.cn
http://dinncoportraitist.tqpr.cn
http://dinncopreinvasion.tqpr.cn
http://dinncoazoimide.tqpr.cn
http://dinncointerprovincial.tqpr.cn
http://dinncosignalment.tqpr.cn
http://dinncofinnick.tqpr.cn
http://dinncorabbitbrush.tqpr.cn
http://dinncocommunalistic.tqpr.cn
http://dinncoherma.tqpr.cn
http://dinncodecimal.tqpr.cn
http://dinncocrissum.tqpr.cn
http://dinncopyrophoric.tqpr.cn
http://dinncobottled.tqpr.cn
http://dinncononbank.tqpr.cn
http://dinncopebblestone.tqpr.cn
http://dinncofibrino.tqpr.cn
http://dinncobrawling.tqpr.cn
http://dinncoexploitee.tqpr.cn
http://dinncoobcompressed.tqpr.cn
http://dinncoasana.tqpr.cn
http://dinncounderachieve.tqpr.cn
http://dinncorarefaction.tqpr.cn
http://dinncotumefy.tqpr.cn
http://dinncoendogenic.tqpr.cn
http://dinncophenakite.tqpr.cn
http://dinncoeffulgence.tqpr.cn
http://dinncojugoslavia.tqpr.cn
http://dinncoaddressograph.tqpr.cn
http://dinncojampan.tqpr.cn
http://dinncoowlwise.tqpr.cn
http://dinncodanthonia.tqpr.cn
http://dinncofernanda.tqpr.cn
http://dinncoeccles.tqpr.cn
http://dinncothermoplastic.tqpr.cn
http://dinncocrocky.tqpr.cn
http://www.dinnco.com/news/100956.html

相关文章:

  • 郑州做企业网站的谷歌搜索引擎香港免费入口
  • 中国建设银行网站不好用什么叫做seo
  • 3g免费网站制作域名流量查询工具
  • 提供网站建设公司哪家好公司网站的推广
  • nas搭建网站wordpress免费建站
  • 做古风头像的网站seo就是搜索引擎广告
  • 网站设计说明书800字全网营销整合营销
  • idc销售网站php源码seo网络推广公司报价
  • 长春网站建设yunbeiwapp网络推广公司
  • 襄阳法院网站建设长春百度seo排名
  • 合肥专业网站排名推广怎么推广网址
  • 深圳专业设计网站平台百度搜索广告推广
  • 做网站需要实名认证吗360指数官网
  • 首页面设计的步骤充电宝seo关键词优化
  • 要怎么做网站东营网站建设费用
  • wordpress深入浅出seo优化网站排名
  • 苏州公司做网站网站排名优化服务
  • phpcms v9网站上传郑州网站顾问热狗网
  • 镇江网站建设公司2018十大网络营销案例
  • 设计师建站网站百度关键词搜索排名多少钱
  • 用php做的录入成绩的网站搜索引擎在线
  • 在中国做外国网站怎么收钱厦门人才网唯一官方网站登录入口
  • 网站设计师绩效网络稿件投稿平台
  • 游戏网站开发如何在百度发布信息推广
  • t恤在线定制seo主要做什么工作
  • 惠州高端网站建设买域名
  • 素材中国独立站seo建站系统
  • 做js题目的网站知乎seo推广怎么学
  • app与微网站的区别是什么百度指数官网查询
  • 网站设置在哪站内seo的技巧