public int indexOf(T x){
if (x!=null){
for (int i=0;i<this.len;i++){
if (this.element[i].equals(x)){
return i;
}
}
}
return -1;
}
public T search(T key) {
return indexOf(key)==-1?null:(T) this.element[indexOf(key)];
}
public T search(T key) {
if (key==null){
return null;
}
Node<T> p=this.head.next;
while (p!=null){
if (p.data.equals(key)){
return p.data;
}
p=p.next;
}
return null;
}
public static<T> int binarySearch(Comparable<T>[] values,int begin,int end,T key) {
if (key != null) {
while (begin <= end) {
int mid = (begin + end) / 2;
if (values[mid].compareTo(key) == 0) {
return mid;
}
if (values[mid].compareTo(key) < 0) {
begin = mid + 1;
}
if (values[mid].compareTo(key) > 0) {
end = mid - 1;
}
}
}
return -1;
}
public static int binarySearch(int[] arrays, int key) {
if (arrays == null || arrays.length == 0) {
return -1;
}
int start=0,end=arrays.length-1;
while (start <=end) {
int mid = (start + end) / 2;
if (arrays[mid] == key) {
return mid;
}
if (arrays[mid] < key) {
start = mid + 1;
}
if (arrays[mid] > key) {
end = mid - 1;
}
}
return -1;
}
private static String[] keyWords={"abstract","assert","boolean","break","byte","case",
"catch","char","continue","default","do","double","else","extend","false","final",
"finally","float","for","if","implements","import","instaceof","in","interface",
"long","native","new","null","package","private","protectd","public","return","short",
"static","super","switch","synchronized","this","throw","transient","true","try","void","volatile","while"};
private static class IndexItem implements Comparable<IndexItem>{
String frist;
int start;
public IndexItem(String frist,int start){
this.frist=frist;
this.start=start;
}
public int compareTo(IndexItem o) {
return this.frist.compareTo(o.frist);
}
private static IndexItem[] index;索引表
static {
index = new IndexItem[26];
int i = 0, j = 0, size = 0;
for (i = 0; j < keyWords.length && i < index.length; i++) {
char ch = keyWords[j].charAt(0);
IndexItem item = new IndexItem(ch + "", j);
if (item != null) {
index[i] = item;
size++;
}
j++;
while (j < keyWords.length && keyWords[j].charAt(0) == ch) {
j++;
}
}
int oldCount = index.length;利用trimTosize方法对数组进行压缩
if (size < oldCount) {
IndexItem[] items = index;
index = new IndexItem[size];
for (int m = 0; m < size; m++) {
index[m] = items[m];
}
}
}
public static boolean isKeyWord(String str){
IndexItem indexItem=new IndexItem(str.substring(0,1),-1);
int pos=BSArry.binarySearch(index,indexItem);
int begin=index[pos].start;
int end;
if (pos==index.length-1){
end=keyWords.length-1;
}else {
end=index[pos+1].start-1;
}
return BSArry.binarySearch(keyWords,begin,end,str)>=0;
}
public class HashSet<T> {
private SingleLinkedList<T>[] table;
public HashSet(int size) {
this.table = new SingleLinkedList[Math.abs(size)];
for (int i = 0; i < table.length; i++) {
table[i] = new SingleLinkedList<T>();//制造单链表
}
}
public HashSet() {
this(97);
}
private int hash(T x) {//利用hashCode解决
int key = Math.abs(x.hashCode());
return key % table.length;
}
public void insert(T x) {
this.table[hash(x)].insert(0, x);
}
public void remove(T x) {
this.table[hash(x)].remove(x);
}
public T search(T key) {
return table[hash(key)].search(key);
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有