小编Ric*_*ard的帖子

ArrayList,java.这两个构造函数之间有什么区别

我是一个仍然在java的新手,你能告诉我这两个构造函数之间的区别吗?

第一:

public class Plan
{

   ArrayList<Point2D> points;

   public Plan(ArrayList<Ponto2D> points)
   {
       this.points = new Arraylist<Point2D>(points);
   }

}
Run Code Online (Sandbox Code Playgroud)

这个:第二个:

public class Plan
{

    public Plan(ArrayList<Point2D> lpoints)
    {
        points = new ArrayList<Point2D>();
        for(Point2D p : lpoints) point.add(p.clone());
    }

}
Run Code Online (Sandbox Code Playgroud)

java

5
推荐指数
2
解决办法
167
查看次数

交换数组函数的两个元素

你能告诉我这有什么问题吗?为什么交换功能不起作用?

void swap(int a[], int b, int c) {
    int temp = a[b];
    a[b] = a[c];
    a[b] = temp;
}

void bubble1 (int a[], int N){
    int i;
    for(i=0;i<N-1;i++){
        if(a[i]>a[i+1]){
            swap(a,i,i+1);
        }
    }
}


void main() {
    int N = 11;
    int a[12]={5,3,12,4,25,10,14,35,2,8,13};

    bubble1 (a,N);

    int i;
    for(i = 0; i < N; i++){
        printf("%d\n",a[i]);
    }
}
Run Code Online (Sandbox Code Playgroud)

如果我不使用交换功能并在“气泡”功能中手动进行交换,它就可以工作。但是,如果我使用交换它不起作用,即使它完全相同。我在这里做错了什么?

c

4
推荐指数
1
解决办法
2万
查看次数

十进制数中的1位数

如何编写一个函数来返回对应十进制数的1位数?也许是平方根函数?类型应该是这样的:

bits :: Int -> Int
Run Code Online (Sandbox Code Playgroud)

编辑:厌倦了

uns :: Int -> Int
uns  0 = 0
uns 1 = 1
uns x | mod x 2 == 1 = 1 + uns (div x 2)
      | otherwise = uns (div x 2)
Run Code Online (Sandbox Code Playgroud)

haskell

2
推荐指数
2
解决办法
336
查看次数

标签 统计

c ×1

haskell ×1

java ×1