Putting a composite statement in the condition of a for loop

前端 未结 6 1160
一整个雨季
一整个雨季 2021-01-18 18:02

I have a contrived example to demonstrate the request for a specific functionality - I wonder if anyone has a clever trick to do this.

The following is a problem one

6条回答
  •  我在风中等你
    2021-01-18 18:52

    "Brute force" and ternary condition solution have the same complexity, but the second one is less "readable".

    You can do a simple method print:

     void print() {
        int i = 0;
        for(i=0; i != size - 1; ++i) {
          printf("%i ",i);
        }
        printf("%i\n", i);
     }
    

    I think it is efficient and readable too.
    In this way you reduce cyclomatic complexity of your alghotitm.

提交回复
热议问题