CPP-Programs- icon indicating copy to clipboard operation
CPP-Programs- copied to clipboard

BucketSort

Open YudhveerCAIN opened this issue 1 year ago • 0 comments

  1. Dynamic Array Declaration: The program uses float arr[n], but this isn’t valid in standard C++ since arrays can't be dynamically sized this way. You should use std::vector instead to handle the dynamic size.
  2. Bucket Index Calculation: The code calculates the bucket index with int(size * array[i]), assuming all values are between 0 and 1. If any values fall outside this range, it could lead to out-of-bounds errors. You need to ensure the input values are within the expected range or scale them appropriately.
  3. Inefficient Element Removal: The program uses bucket[i].erase(bucket[i].begin()) repeatedly in a loop. This is inefficient because it shifts elements each time. A better approach is to iterate through the bucket and directly reassign values.
  4. Lack of Input Validation: The program doesn’t check if the user inputs valid values between 0 and 1. Adding validation helps prevent errors if someone enters an out-of-range number.

YudhveerCAIN avatar Oct 16 '24 18:10 YudhveerCAIN