- 浏览: 116784 次
- 性别:
- 来自: 上海
最新评论
-
wayswssb:
不好意思 看错了 应该是正确的。。。
Java实现 希尔排序 -
wayswssb:
这算法有问题 感觉 为什么每次都拿temp比较呢
Java实现 希尔排序 -
陈修恒:
最近也碰到这个问题了, 好纠结啊 ..
java.net.SocketException: No buffer space available (maximum connections reached -
bo_hai:
找到了我想要学习的知识点。有java实现算法和用C实现是有所不 ...
java 实现 插入排序 希尔排序 冒泡排序 快速排序 堆排序 归并排序 【完美版】 -
ahutzh:
学习一下
java多线程 银行取款
文章列表
public class ShellSort {
public static void shellSort(Comparable[] data){
int j;
for(int gap = data.length / 2; gap > 0; gap /= 2){
for(int i = gap; i < data.length; i ++){
Comparable tmp = data[i];
for(j = i; j >= gap && tmp.compareTo(data[j - gap] ...
- 2009-05-11 17:15
- 浏览 1108
- 评论(0)
public class InsertionSort2 {
public static void insertSort(Comparable[] data){
int j;
for(int p = 1; p < data.length; p++){
Comparable key = data[p];
for(j = p; j > 0 && (key.compareTo(data[j-1]) < 0); j--)
data[j] = data[j-1];
data[j] = key;
}
}
...
- 2009-04-28 18:17
- 浏览 3776
- 评论(0)
//计算两个随机小于等于n的互异正整数互素 的 概率,
public class ProbRelPrim {
public static double probRelPrim(int n){
int rel =0;
int tot = 0;
for(int i = 1; i <= n; i++)
for(int j = i + 1; j <= n; j++){
tot++;
if(gcd(i, j) == 1)//最大公约数为一,则互素,
rel++;
}
return (double ...
- 2009-04-24 21:15
- 浏览 1563
- 评论(0)
//幂运算,
public class POW {
public static long pow(long x, int n){
if(n == 0)
return 1;
if(n == 1)
return x;
if(isEven(n))//是否 偶数,
return pow(x * x, n / 2);
else
return pow(x * x, (n - 1) / 2) * x;
}
public static boolean isEven(int n){
if(n % 2 == 0)
...
- 2009-04-24 20:57
- 浏览 935
- 评论(0)
//欧几里得算法,计算最大公因数,
public class GCD {
public static long gcd(long m, long n){
while(n != 0){
long rem = m % n;
m = n;
n = rem;
}
return m;
}
public static void main(String[] args){
long x = 1989;
long y = 1590;
long z = gcd(x,y);
System.out.pri ...
- 2009-04-24 20:32
- 浏览 1465
- 评论(0)
折半查找,二分查找,
- 博客分类:
- 数据结构与算法
//折半查找,二分查找,
public class BinarySearch {
public static int binarySearch(int[] a, int x){
int low = 0;
int high = a.length - 1;
while(low <= high){
int mid = (low + high) / 2;
if(a[mid] > x)
high = mid - 1;
else if(a[mid] < x)
low = mid + 1;
...
- 2009-04-24 20:12
- 浏览 854
- 评论(0)
//求最大子序列和问题,
public class MaxSubSum{
public static int maxSubSum(int[] a){
int maxSum = 0, thisSum = 0;
for(int j = 0; j < a.length; j++){
thisSum += a[j];
if(thisSum > maxSum)
maxSum = thisSum;
else if(thisSum < 0)
thisSum = 0;
}
re ...