Код: Выделить всё
package com.vmg.p_009_02;
import java.sql.SQLOutput;
/**
* Created by Admin on 02.05.2015.
*/
public class main {
public static void main (String[] args) {
class HighArray
{
private long[] a; // Ссылка на массив
private int nElems; // Количество элементов в массиве
//-----------------------------------------
public HighArray (int max) // Конструктор
{
a = new long[max]; // Создание массива
nElems = 0; // Пока нет ни одного элемента
}
//----------------------------------------------
public boolean find(long searchkey)
{
int j;
for (j=0;j<nElems;j++)
if (a[j]== searchkey){ // Да , значение найдено
break;
}
if (j==nElems) {
return false; // Достигнут последний элемент
} else {
return true;
}
}
//----------------------------------------------------
public void insert(long value){
a[nElems] = value ;
nElems ++;
}
//-----------------------------------------------------
public boolean delete(long value){
int j;
for (j=0;j<nElems;j++){
if (value==a[j]) {
break;
}
}
if (j==nElems){
return false;
} else {
for (int k=j;k<nElems;k++){
a[k]=a[k+1];
}
nElems--;
return true;
}
}
//---------------------------------------------------------
public void display () {
int j;
for (j=0;j<nElems;j++){
System.out.println(a[j]+" ");
System.out.println(" ");
}
}
//-------------------------------------------------------
} // КОНЕЦ КЛАССА HighArray
///////////////////////////////////////////////////////////////
class HighArrayApp
{
public void main(String[] args) {
int maxSize = 100 ;
HighArray arr;
arr = new HighArray(maxSize);
arr.insert(11);
arr.insert(17);
arr.insert(21);
arr.insert(34);
arr.insert(6);
arr.insert(107);
arr.insert(1337);
arr.insert(89);
arr.insert(75);
arr.insert(99);
arr.display();
int searchKey = 107 ;
if (arr.find(searchKey)) {
System.out.println("Found "+searchKey);
} else {
System.out.println("Can't find "+searchKey);
}
arr.delete(107);
arr.delete(89);
arr.delete(100);
arr.display();
}
}
}
}