java版 2分查找
/**
* 采用2分法实现有序数组的增删查
* 由于数组定义了大小就不能再改了 所以我们重新定义了size()方法;
* 将数据组成了一个对象
* @author leader
* 2009-11-3
*/
class Array
{
public static int maxsize ;//数组的长度的最大值
public static int realsize;
int [] array ;//数组
public Array (int maxsize)
{
//初始化这个类
this.maxsize = maxsize;
this.array = new int [this.maxsize];
this.realsize = 0 ;
}
/**
* 给数组添加数据
*/
public void insert (int ins)
{
//当数组还有空间的时候才能往里面插入数据
int len = this.realsize;
if(len == maxsize)
{
System.out.println("数组已满");
}
//由于是有序数组 所以要给新添加进来的数字放到排序后的位置
int i = 0;
for ( ;i<this.realsize;i++)
{
if(array[i]>ins)
{
//插入的数字小于数组中的某个成员的时候 就可以放在这个数字的前面 应为他是有序的排列的
break;
}
}
//讲这个数据以后的数据向后一位 从最后开始移
for (int j =this.realsize ;j>i;j--)
{
array[j] = array[j-1];
}
array[i]=ins;//将插入的数字放在正确的位置
this.realsize ++;//将数组长度加一
}
/**
* 数组的大小只是给人看的
* @return
*/
public int size ()
{
return this.realsize;
}
public void display ()
{
for (int i = 0 ;i<this.realsize;i++)
{
System.out.println(array[i]);
}
}
public void delete (int del)
{
int i = 0;
for ( ;i<this.realsize;i++)
&
相关文档:
1.java过滤器对ext异步请求跳转
用户访问超时
解决两种情况下的用户访问超时。
a)普通http请求的session超时。
b)异步http请求的session超时,使用ext后大部分的界面刷新都是异步的ajax请求。
不管是那种类型的http请求总是可以由一个过滤器来捕捉。
分类:普通http请求的header参数中没有x-requested-with: ......
1.创建文件夹
File myFolderPath = new File(%%1);
try {
if (!myFolderPath.exists()) {
myFolderPath.mkdir();
}
}
catch (Exception e) {
System.out.println("新建目录操作出错");
e.printStackTrace();  ......
41、是否可以继承String类?
String类是final类故不可以继承。
42、swtich是否能作用在byte上,是否能作用在long上,是否能作用在String上?
switch(expr1)中,expr1是一个整数表达式。因此传递给 switch 和 case 语句的参数应该是 int、 short、 char 或者 byte。long,st ......
1.1 不用new关键词创建类的实例
用new关键词创建类的实例时,构造函数链中的所有构造函数都会被自动调用。但如果一个对象实现了Cloneable接口,我们可以调用它的clone()方法。clone()方法不会调用任何类构造函数。
在使用设计模式(Design Pattern)的场合,如果用Factory模式创建对象,则改用clone( ......
集合Collection接口
--Collection 是任何对象组,元素各自独立,通常拥有相同的套用规则。Set List由它派生。
基本操作 增加元素add(Object obj); addAll(Collection c);
删除元素 remove(Object obj); removeAll(Collection c);
求交集 retainAll(Collection c);
删除元素 remove(Object obj); removeAll(Collectio ......