0

I tried using bubble sort for Reflect, it goes something like this

pretend I defined temp here for (int i = 0; i = height; i++) for (int j = 0; j = width - 1; j++) for (int k = 0; k = width - 1; k++) temp = image[i][k+1]; image[i][k+1] = image[i][k]; image[i][k] = image[i][k+1];

It should basically bubble sort in a way that the image will reflect. Why is the image still unchanged?

1
  • Basically 3 for loops, looping the height, then the width -1 then width -1 again to do bubble sort left to right for the whole image
    – Aaron Tan
    Commented Jan 13, 2022 at 2:23

1 Answer 1

0

Bubble sort seems quite an inefficient way to go about reflecting the image. I suggest that, for the problem set, you try to think of a more direct way to achieve the same thing.

But regarding your code:

  1. note that you define temp, but then don't use it. Look at your code and see where it should be used;
  2. there is a problem in your for loop declarations. Remember that the middle part is the condition that has to be satisfied for the loop to continue, e.g. for (int x = 0; x < 20; x++).

(I realise I'm not strictly answering your question, but because this is for assessment, I'd rather guide you than just blurt out the answers)

1
  • Thank you! But I realised my issue, bubble sort doesn’t reflect the image At all… it just brings the first row to the last row and the rest of the rows will literally stay the same lol… I got it! Thanks!
    – Aaron Tan
    Commented Jan 14, 2022 at 15:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .