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

php网站优点china东莞seo

php网站优点,china东莞seo,无人在线电视剧免费观看,网站cn和com哪个做站好💕"世事犹如书籍,一页页被翻过去。人要向前看,少翻历史旧账。"💕 作者:Mylvzi 文章主要内容:数据结构之顺序表的模拟实现 /*** Created with IntelliJ IDEA.* Description:* User: 绿字* Date:…

 💕"世事犹如书籍,一页页被翻过去。人要向前看,少翻历史旧账。"💕

作者:Mylvzi 

 文章主要内容:数据结构之顺序表的模拟实现 

 

/*** Created with IntelliJ IDEA.* Description:* User: 绿字* Date: 2023-10-12* Time: 8:53*/
import java.util.*;
/*** 顺序表详解*/
public class MyArrayList {private int[] elem;// 存放数据的数组private int usedSize;// 有效数据个数public static final int DEFAULT_SIZE = 10;// 初始化顺序表public MyArrayList() {this.elem = new int[DEFAULT_SIZE];}public MyArrayList(int ininCapacity) {// 自定义数组的大小this.elem = new int[ininCapacity];}// 打印顺序表public void display() {for (int i = 0; i <this.usedSize ; i++) {System.out.print(this.elem[i] +" ");}}// 添加数据  默认是在末尾添加public void add(int data) {// 满了要扩容if(isFull()) {this.elem = Arrays.copyOf(this.elem,2*this.elem.length);}this.elem[usedSize] = data;this.usedSize++;}// 判断是否已满public boolean isFull() {if(this.usedSize == this.elem.length) {return true;}return false;}// 在 pos 位置新增元素public void add(int pos, int data) {// pos位置要合法if(pos<0 || pos>this.usedSize) {throw new RuntimeException(pos+"位置不合法");}if(isFull()) {this.elem = Arrays.copyOf(this.elem,2*this.elem.length);}for (int i = this.usedSize-1; i >=pos ; i--) {this.elem[i+1] = this.elem[i];}this.elem[pos] = data;this.usedSize++;}// 判定是否包含某个元素public boolean contains(int toFind) {for (int i = 0; i <this.usedSize ; i++) {if(this.elem[i] == toFind) {return true;}}System.out.println("数组不包含该元素");return false;}// 查找某个元素对应的位置public int indexOf(int toFind) {for (int i = 0; i <this.usedSize ; i++) {if(this.elem[i] == toFind) {return i;}}System.out.println("数组不包含该元素");return -1;}// 检查pos位置是否合法private void checkPosLegal(int pos) {if(pos<0 || pos>=this.usedSize) {throw new posOutOfBoundException(pos+" 位置不合法");}}// 获取 pos 位置的元素public int get(int pos) {checkPosLegal(pos);return this.elem[pos];}// 给 pos 位置的元素设为 value  pos位置必须含有元素public void set(int pos, int value) {checkPosLegal(pos);this.elem[pos] = value;}//删除第一次出现的关键字keypublic void remove(int toRemove) {int index = indexOf(toRemove);for (int i = index; i <this.usedSize-1 ; i++) {this.elem[i] = this.elem[i+1];}this.usedSize--;}// 获取顺序表长度public int size() {return this.usedSize;}// 清空顺序表public void clear() {// 如果是引用类型所有的引用都要置空
//        for (int i = 0; i <this.usedSize; i++) {
//            this.elem[i] = null;
//        }this.usedSize = 0;}
}
/*** Created with IntelliJ IDEA.* Description:* User: 绿字* Date: 2023-10-12* Time: 10:49*/
public class posOutOfBoundException extends RuntimeException{public posOutOfBoundException() {}public posOutOfBoundException(String message) {super(message);}
}
/*** Created with IntelliJ IDEA.* Description:* User: 绿字* Date: 2023-10-12* Time: 9:02*/
public class Test1 {public static void main(String[] args) {MyArrayList myArrayList = new MyArrayList(5);myArrayList.add(1);myArrayList.add(2);myArrayList.add(3);myArrayList.add(4);
/*        System.out.println(myArrayList.size());myArrayList.remove(1);System.out.println(myArrayList.size());*/
//        myArrayList.add(100,99);
/*        myArrayList.set(0,999);myArrayList.remove(999);myArrayList.remove(2);myArrayList.remove(3);myArrayList.remove(4);myArrayList.remove(5);*//*        System.out.println(myArrayList.get(0));System.out.println(myArrayList.get(-1));System.out.println(myArrayList.get(999));*/
//        System.out.println(myArrayList.contains(2));
//        System.out.println(myArrayList.indexOf(2));
//
/*        myArrayList.add(0,999);myArrayList.add(0,999);myArrayList.add(0,999);myArrayList.add(0,999);myArrayList.add(0,999);*/
myArrayList.clear();myArrayList.display();}
}

http://www.tj-hxxt.cn/news/106928.html

相关文章:

  • 为什么选择做游戏网站网站运营推广方式
  • 网站页面背景cdq百度指数
  • 做网站建设要什么证营销公司
  • 减肥网站如何做长尾关键词查询
  • 男做基视频网站东方网络律师团队
  • 济宁检出阳性259人seo优化自动点击软件
  • 现在网站建设还用测浏览器吗在线网站流量查询
  • 网站开发工程师的工作描述安卓系统优化大师
  • 网站测试结果分析免费男女打扑克的软件
  • 武义建设工程网站网页设计首页制作
  • 网站感谢页面如何网站推广
  • 制作公司网站怎样收费销售找客户的app
  • 网站建设中单页代码在百度怎么发广告做宣传
  • 活动手机网站开发网店交易平台
  • 在东莞做网站优化方案丛书官网
  • 网站首页ui高明公司搜索seo
  • 定制型网站建设多少钱即刻搜索引擎入口
  • 网络营销品牌公司优化的概念
  • 一个网站值多少钱哈尔滨网站制作软件
  • ps做购物小网站百度搜索热度
  • phpcms v9 网站搬家赣州seo外包怎么收费
  • 盘锦建设小学网站站长工具ping检测
  • 在哪里可以查公司注册信息优化大师百科
  • google seo推广seo交流中心
  • 同性做视频网站网络推广网站程序
  • 网站 数据库选择北京网站优化公司
  • 贵州两学一做网站如何做好seo基础优化
  • 建设部质监局网站steam交易链接在哪复制
  • a站网址软文广告属于什么营销
  • 怎么做网站教程网站建设公司