Posts Tagged ‘java’

兩個 class 加兩個 jsp …
功能極其有限 lol
source 在這裡

Friday, April 17th, 2009 at 12:03 | 0 comments
Categories: Programming
Tags: ,

Suppose you have asterisk 1.6 with freepbx and you are developing with the latest asterisk-java library. Somehow you wanna perform different tasks based on calls coming through different SIP trunks.
When there’s a new incoming call, asterisk-java will trigger a newChannelEvent, but there’s no information in this event that can be used for distinguish from which [...]

Thursday, March 19th, 2009 at 11:28 | 1 comment
Categories: Programming, linux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
public void quicksort(int[] d, int lo, int hi){
if(lo<hi){
int pivotIndex=partition(d, lo, hi);
quicksort(d,lo,pivotIndex-1);
quicksort(d,pivotIndex+1,hi);
}
public int partition(int[] d,int lo, int hi){
intStack smaller = new intStack();
intStack larger = new intStack();
int pivot = d[hi];
for(int i=lo;i<hi;i++){
if(d[i]<pivot)
smaller.push(d[i]);
else
larger.push(d[i]);
}
int i=lo;
while(!smaller.isEmpty()){
d[i]=smaller.pop();
i++;
}
d[i] = pivot;
int pivotIndex = i;
i++;
while(!larger.isEmpty()){
d[i] = larger.pop();
i++;
}
return pivotIndex;
}
}

Tuesday, June 10th, 2008 at 21:55 | 0 comments
Categories: Programming

The codes might be not optimized, and the first elements of all arrays are chosen as the pivots, which will cause a tremendous slow-down when the array is sorted already.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
public static void swap(int[] ar, int a, int b){
int tmp = ar[a];
ar[a] = ar[b];
ar[b] = tmp;
}
public static int partition(int[] a, int left, int right) {
int pivot=a[left];
int [...]

Monday, June 2nd, 2008 at 08:21 | 0 comments
Categories: Programming
TOP