1, delete principle:
Package Com.struct.array; /** * @ Description Base Array * @ Project name Java_datastruct * @ Package Name Com.struct.array * @ class name Basicarray * @author
Chenlin * @date June 20, 2011 PM 8:41:21 */public class Basicarray {//array private long arr[];
The effective length of the array is private int elements;
The maximum length of the array is private int max;
Initializes public basicarray (int max) {this.max = max;
arr = new Long[max];
/** * Insert Data * @param value/public void Insert (Long value) {if (Elements > Max) {
throw new ArrayIndexOutOfBoundsException ();
} arr[elements] = value;
Elements + +;
/** * Show All data */public void display () {System.out.print ("[");
for (int i = 0; i < elements i++) {System.out.print ("" + arr[i]);
} System.out.println ("]"); /** * Find index based on value * @param value * @return/public int SearcH (Long value) {int i;
for (i = 0; i < elements; i++) {//represent found, exit loop if (arr[i] = = value) {break;
} if (i = = elements) {return-1;
}else {return i; }/** * Find numeric value based on index * @param index * @return/public long get (int index) {if Dex > Elements | |
Index < 0) {throw new arrayindexoutofboundsexception ();
return Arr[index]; /** * Changes the value on Index * @param index * @param value/public void change (int index, Long value)
{if (Index > elements | | Index < 0) {throw new arrayindexoutofboundsexception ();
} Arr[index] = value; /** * Delete data on index * @param index */public void Delete (int index) {if (Index > Elemen ts | | Index < 0) {throw new arrayindexoutofboundsexceptIon ();
}else {for (int i = index; i < elements; i++) {Arr[i] = arr[i + 1];
} Elements--;
} public static void Main (string[] args) {Basicarray array = new Basicarray (30);
Array.insert (22);
Array.insert (12);
Array.insert (34);
Array.insert (44);
Array.insert (86);
Array.insert (57);
Display Array.display ();
System.out.println ("======================================");
Find System.out.println (Array.search (12));
System.out.println ("======================================");
Modification of Array.change (2, 50);
Array.display ();
System.out.println ("======================================");
Delete Array.delete (3);
Array.display (); }
}