Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab6 Code Review #4

Open
junyuanjun opened this issue Nov 1, 2016 · 0 comments
Open

Lab6 Code Review #4

junyuanjun opened this issue Nov 1, 2016 · 0 comments

Comments

@junyuanjun
Copy link
Member

Code Review的文档请上传至ftp的Code Review/lab6 文件夹中。
首先大家先看看Lab6示例代码
这个lab的实现方式其实非常多样,在示例代码中给出的只是一种方案。

下面这段代码也是解决Lab 6中Problem 1的一种方案(后文简称“代码2”)

    public static int compare(char[] a, char[] b) {
        int i = 0;
        while (i < a.length && a[i] == '0')
            i++;
        int indexA = i;

        i = 0;
        while (i < b.length && b[i] == '0')
            i++;
        int indexB = i;

        if (a.length - indexA < b.length - indexB) {
            return -1;
        } else if (b.length - indexB < a.length - indexA) {
            return 1;
        } else {
            for (i = indexA; i < a.length; i++) {
                int j = i + indexB - indexA;
                if (a[i] > b[j]) {
                    return 1;
                }
                else if (a[i] < b[j]) {
                    return -1;
                }
            }
        }
        return 0;
    }

请大家结合示例代码、代码2以及自己的代码,回答如下几个问题:

  1. 示例代码中写得好的地方有哪些?你觉得是否还可以写得更好?
  2. 代码2有哪些写得好的地方?你觉得这段代码哪里还可以提高?
  3. 对比自己的代码,自己的代码有哪些亮点?和示例代码以及代码2比较完之后,觉得自己的代码怎样做可以更好?

最后重申一下:Code Review的文档请上传至ftp的Code Review/lab6 文件夹中。☘️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant