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

尤溪县建设局网站专做定制的网站

尤溪县建设局网站,专做定制的网站,企业邮箱什么格式,wordpress 插件 图片#x1f495;世事犹如书籍#xff0c;一页页被翻过去。人要向前看#xff0c;少翻历史旧账。#x1f495; 作者#xff1a;Mylvzi 文章主要内容#xff1a;数据结构之顺序表的模拟实现 /*** 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(pos0 || posthis.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[i1] 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(pos0 || posthis.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[i1];}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.hkea.cn/news/14396846/

相关文章:

  • 江西营销网站建设小程序公众号开发方案
  • 做百度还是阿里网站好建设施工合同范本
  • 正规网站建设服务中心罗定市城乡建设局网站
  • 果洛营销网站建设多少钱坑人的网站链接怎么做
  • 社交(sns)网站的完整设计思路名字logo设计免费
  • 手机网页制作与网站建设wordpress 评论插件
  • 广州物流网站开发html产品介绍网页设计代码作业
  • 郑州 手机网站淘客推广渠道
  • 惠州公司做网站网络营销方案的制定
  • 网站的常用技术有哪些wap版网站建设方案
  • 商城网站建设报价北京中交建设工程咨询有限公司网站
  • asp.net网站开发案例教程网站如何做自适应
  • 景区网站策划书手游推广平台代理
  • 市场调查 网站建设网站建设制作设计优化
  • wordpress进入仪表盘做好的网站怎么优化
  • 东莞市建网站一分钟赚50元的游戏
  • 重生做皇帝小说网站北京市网络科技有限公司
  • 网站开发所需经费上海设计院排名
  • 2017湖北建设教育协会网站中国网直播
  • 深圳专业专业网站设计公司做网站外包公司
  • 负责公司网站产品的开发及整理网站开发有哪些常用工具
  • 重庆建设车业官方网站wordpress 下载站插件
  • 图书馆网站建设报告网站建设搜索优化
  • 宣传部总结网站建设建站公司分析
  • 什么是网站开发时间进度表求和萝莉做的网站
  • 动漫制作专业专科龙岗seo网络推广
  • 肇庆网站开发哪家专业成crm软件
  • 30天网站建设全程实录 pdf西安家政公司网站建设
  • 百度工具网站改版没有网站域名备案信息
  • 安阳网站建设设计网上注册营业执照怎么注册