用java編寫簡單計算器,java 順序表的實現_順序表的簡單實現(Java)

 2023-11-18 阅读 20 评论 0

摘要:采用Java實現數據結構中的順序表/***Apr 15, 2013*Copyright(c)JackWang*All rights reserve用java編寫簡單計算器、*@Author JackWang*/package com.example.list;/*** 順序表的實現* @author Administratorjava優先級排序?**/public class MySeqList {private Obje

采用Java實現數據結構中的順序表

/**

*Apr 15, 2013

*Copyright(c)JackWang

*All rights reserve

用java編寫簡單計算器、*@Author JackWang

*/

package com.example.list;

/**

* 順序表的實現

* @author Administrator

java優先級排序?*

*/

public class MySeqList {

private Object[] obj; //存儲元素,初始長度為10

private int len; //記錄順序表的長度

private final int maxSize = 10;

java自帶的排序方法?/**

* 初始化線性表

*/

public MySeqList() {

this.obj = new Object[10];

this.len = 0;

javafinal關鍵字,this.clear();

}

/**

* 判斷線性表是否為空

* @return 空返回true

*/

java編寫記事本程序、public boolean isEmpty(){

if (len == 0) {

return true;

}

return false;

}

java實現多態的機制?/**

* 判斷線性表是否已滿

* @return 滿返回 true

*/

public boolean isFull(){

if (len == maxSize) {

java簡單圖書管理系統,return true;

}

return false;

}

/**

* 返回線性表的長度

java.awt、* @return 線性表的長度

*/

public int length(){

return len;

}

/**

java web項目?* 清空線性表

*/

public void clear() {

for (int i = 0; i < obj.length; i++) {

obj[i] = null;

}

java接口的實例,}

/**

* 添加元素

* @param i 要添加元素的腳標

* @param o 要添加的元素

*/

java建立一個順序表。public void insert(int i,Object o){

if (i <1) {

throw new RuntimeException("腳標不規范!");

}

if (obj[i-1] != null) {

for(int j = len-1;j>i;j--){

java工作流框架哪個好。obj[j+1] = obj[j];

}

obj[i] = o;

len++;

return;

}else {

用java實現簡單計算器,obj[i-1] = o;

len++;

return;

}

}

/**

java數據結構順序表逆置?* 刪除元素

* @param i 要刪除的元素索引

*/

public void delete(int i){

if (i > len || i <1) {

throw new RuntimeException("腳標不規范!");

java如何運行、}

for(int j = i;j

obj[i-1]=obj[i];

}

obj[len-1] = null;

len--;

java簡單程序代碼大全?}

/**

* 修改元素

* @param i 要修改元素的腳標

* @param newObj 要修改的值

*/

public void update(int i,Object newObj){

if (i > len || i <1) {

throw new RuntimeException("腳標不規范!");

}

obj[i-1] = newObj;

}

/**

* 查找元素

* @param o 要查找的元素

* @return 查到元素的索引

*/

public int find(Object o){

for (int i = 0; i < obj.length; i++) {

if(o.equals(obj[i])){

return i+1;

}

}

return -1;

}

/**

* 當前元素的前一個元素的索引

*/

public int previous(int i){

if (i > len || i <1) {

throw new RuntimeException("腳標不規范!");

}

if( i== 1){

return len;

}

return i-1;

}

/**

* 當前元素的后一個元素的索引

*/

public int next(int i){

if (i > len || i <1) {

throw new RuntimeException("腳標不規范!");

}

if( i == len){

return 1;

}

return i+1;

}

/**

* 遍歷輸出線性表

* @return

*/

public void print(){

for (int i = 0; i < obj.length; i++) {

System.out.println(obj[i]+" ");

}

System.out.println();

}

/**

* 得到特定腳標的元素

* @param i

* @return

*/

public Object get(int i){

if (i > len || i <1) {

throw new RuntimeException("腳標不規范!");

}

return obj[i-1];

}

}

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/5/178513.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息