data order

data order,第1张

data order

head cut

package data;


public class 十七 {
    private int[] elementData;
    private int size;


    public 十七() {
        this.elementData = new int[18];
    }

    public 十七(int size) {
        elementData = new int[size];
    }

     public void addFirst(int data) {
        for (int i = size - 1; i >= 0; i--) {
            elementData[i + 1] = elementData[i];

        }
        elementData[0] = data;
        size++;
    }
    public String toString() {
        String ret = "[";
        for (int i = 0; i < size; i++) {
            ret += elementData[i];
            if (i != size - 1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }

    public void grow() {

    }

    public static void main(String[] args)
    {
        十七 十七=new 十七();
        十七.addFirst(1);
        十七.addFirst(2);
        十七.addFirst(3);
        System.out.println(十七);

    }
}

package data;


import java.util.Arrays;

public class 十七 {
    private int[] elementData;
    private int size;


    public 十七() {
        this.elementData = new int[18];
    }

    public 十七(int size) {
        elementData = new int[size];
    }

     public void addFirst(int data) {
        if (size==elementData.length){
            grow();
        }
        for (int i = size - 1; i >= 0; i--) {
            elementData[i + 1] = elementData[i];

        }
        elementData[0] = data;
        size++;
    }

  
  public void addLast(int Data) {

if (size==elementData.length)
{grow();
}
elementData[size]=Data;
  size++;
  }
    public void addIndex(int index, int data) {

    }

   

    public String toString() {
        String ret = "[";
        for (int i = 0; i < size; i++) {
            ret += elementData[i];
            if (i != size - 1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }

    public void grow() {
int oldlength=elementData.length;
int newLength=oldlength<<1;
       elementData= Arrays.copyOf(elementData,newLength);
    }
    public int getSize() {
        return size;
    }
    public static void main(String[] args)
    {
        十七 十七=new 十七();
        十七.addFirst(1);
        十七.addFirst(2);
        十七.addFirst(3);
        十七.addLast(4);
        十七.addLast(5);
        十七.addLast(6);
        System.out.println(十七);

    }
}



cut final

package data;


import java.util.Arrays;

public class 十七 {
    private int[] elementData;
    private int size;


    public 十七() {
        this.elementData = new int[18];
    }

    public 十七(int size) {
        elementData = new int[size];
    }

     public void addFirst(int data) {
        if (size==elementData.length){
            grow();
        }
        for (int i = size - 1; i >= 0; i--) {
            elementData[i + 1] = elementData[i];

        }
        elementData[0] = data;
        size++;
    }

  
  public void addLast(int Data) {

if (size==elementData.length)
{grow();
}
elementData[size]=Data;
  size++;
  }
    public void addIndex(int index, int data) {

    }

   

    public String toString() {
        String ret = "[";
        for (int i = 0; i < size; i++) {
            ret += elementData[i];
            if (i != size - 1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }

    public void grow() {
int oldlength=elementData.length;
int newLength=oldlength<<1;
       elementData= Arrays.copyOf(elementData,newLength);
    }
    public int getSize() {
        return size;
    }
    public static void main(String[] args)
    {
        十七 十七=new 十七();
        十七.addFirst(1);
        十七.addFirst(2);
        十七.addFirst(3);
        十七.addLast(4);
        十七.addLast(5);
        十七.addLast(6);
        System.out.println(十七);

    }
}

cut index

package data;


import java.util.Arrays;

public class 十七 {
    private int[] elementData;
    private int size;


    public 十七() {
        this.elementData = new int[18];
    }

    public 十七(int size) {
        elementData = new int[size];
    }

     public void addFirst(int data) {
        if (size==elementData.length){
            grow();
        }
        for (int i = size - 1; i >= 0; i--) {
            elementData[i + 1] = elementData[i];

        }
        elementData[0] = data;
        size++;
    }

  
  public void addLast(int Data) {
if (size==elementData.length)
{grow();
}
elementData[size]=Data;
  size++;
  }

  public void addIndex(int index, int data) {
if (index<0||index>size){
    System.out.println("Wrong");
    return;
}
if (size==elementData.length)
{
grow();}
if (index==0)
{addFirst(data);
    }
 if (index==size){
addLast(data);
 }
 else {
     for (int i = size-1; i >=index ; i--) {
         elementData[i+1]=elementData[i];
     }
     elementData[index]=data;
     size++;
 }
  }

   

 public String toString() {
        String ret = "[";
        for (int i = 0; i < size; i++) {
            ret += elementData[i];
            if (i != size - 1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }

    public void grow() {
int oldlength=elementData.length;
int newLength=oldlength<<1;
       elementData= Arrays.copyOf(elementData,newLength);
    }
    public int getSize() {
        return size;
    }
    public static void main(String[] args)
    {
        十七 十七=new 十七();
        十七.addFirst(1);
        十七.addFirst(2);
        十七.addFirst(3);
        十七.addLast(4);
        十七.addLast(5);
        十七.addLast(6);
        十七.addIndex(3,44);
        System.out.println(十七);

    }
}


change index


import java.util.Arrays;

public class 十七 {
    private int[] elementData;
    private int size;


    public 十七() {
        this.elementData = new int[18];
    }

    public 十七(int size) {
        elementData = new int[size];
    }

     public void addFirst(int data) {
        if (size==elementData.length){
            grow();
        }
        for (int i = size - 1; i >= 0; i--) {
            elementData[i + 1] = elementData[i];

        }
        elementData[0] = data;
        size++;
    }

  
  public void addLast(int Data) {
if (size==elementData.length)
{grow();
}
elementData[size]=Data;
  size++;
  }

  public void addIndex(int index, int data) {
if (index<0||index>size){
    System.out.println("Wrong");
    return;
}
if (size==elementData.length)
{
grow();}
if (index==0)
{addFirst(data);
    }
 if (index==size){
addLast(data);
 }
 else {
     for (int i = size-1; i >=index ; i--) {
         elementData[i+1]=elementData[i];
     }
     elementData[index]=data;
     size++;
 }
  }

   

 public String toString() {
        String ret = "[";
        for (int i = 0; i < size; i++) {
            ret += elementData[i];
            if (i != size - 1) {
                ret += ",";
            }
        }
        ret += "]";
        return ret;
    }

    public void grow() {
      int oldlength=elementData.length;
int newLength=oldlength<<1;
       elementData= Arrays.copyOf(elementData,newLength);
    }
    public int getSize() {
        return size;
    }
    public int set(int index,int newData){
     if (rangeCheck(index)){
         int oldValue=elementData[index];
         elementData[index]=newData;
         return  oldValue;
     }return -1;
    }

    public boolean rangeCheck(int index){
     if (index<0||index>size){
         System.out.println("Wrong");
         return false;
     }
     return true;
    }
    public static void main(String[] args)
    {
        十七 十七=new 十七();
        十七.addFirst(1);
        十七.addFirst(2);
        十七.addFirst(3);
        十七.addLast(4);
        十七.addLast(5);
        十七.addLast(6);
        十七.addIndex(3,44);
        十七.set(3,444);
        System.out.println(十七);

    }
}

Judge

    public boolean contains(int data){
    for (int i = 0; i  


delete index

public  void remove(int index){
     if (rangeCheck(index)){
         for (int i = index; i  


delete data

public void removevalue(int Value){
      for (int i = 0; i < size; i++) {
          if (elementData[i]==Value)
          { remove(i);
          }
      }
  }
    public static void main(String[] args)
    {
        十七 十七=new 十七();
   十七.addFirst(1);
        十七.addFirst(2);
        十七.addFirst(3);
        十七.addLast(4);
        十七.addLast(5);
        十七.addLast(6);
        十七.addIndex(3,44);
        十七.set(3,2323);
        System.out.println(十七);
        System.out.println(十七.contains(2323));

十七.removevalue(4);
        System.out.println(十七);
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4744158.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-08
下一篇 2022-11-08

发表评论

登录后才能评论

评论列表(0条)

保存