数据结构学习--自定义数组

代码如下:

 1 package DataStruct;
 2 
 3 public class Array {
 4 
 5     private int[] data;
 6     private int[] size;
 7 
 8     public Array(int capacity) {
 9         data = new int[capacity]
10         size = 0
11     }
12 
13 
14     //构造函数,传入数组的容量capacity构造Array
15     public Array() {
16         this(10);
17     }
18 
19     //无参数的构造函数,默认数组的容量是capacity=0
20     public int getSize() {
21         return size;
22     }
23 
24     //获取数据中的元素个数
25     public int getCapatity() {
26         return data.length;
27     }
28 
29     //获取数据的容量
30     public boolean isEmpty() {
31         return size == 0;
32     }
33 
34 }

猜你喜欢

转载自www.cnblogs.com/renran/p/9784812.html