From e0bde664ea0407d3c56ae84b63a4141460d07c0f Mon Sep 17 00:00:00 2001 From: Manikanta P <113213995+manikanta-manii@users.noreply.github.com> Date: Thu, 18 May 2023 01:06:30 +0530 Subject: [PATCH] Update quick-sort.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previous code was having Array Index Bound Error in it , so i made changes in code . Changes made are: 1. pointer i was incrementing if arr[i] is less than or equal to pivot this was leading it cross the boundary , which is at that iteration i will be greater than high . then again while checking condition it was trying to access the high'th element which was giving "Array Index Out Of Bound" error . solution : if ( i<=high && arr[i] <=pivot ) then i++ ; similarly for j pointer : if(j>=low && arr[j] >=pivot) then j-- ; 📌📌 please update this in your web page ........ ❤️❤️ If possible give some credit : https://github.com/manikanta-manii --- content/data-structures-algorithms/quick-sort.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/content/data-structures-algorithms/quick-sort.md b/content/data-structures-algorithms/quick-sort.md index fd8398e..77139da 100644 --- a/content/data-structures-algorithms/quick-sort.md +++ b/content/data-structures-algorithms/quick-sort.md @@ -174,12 +174,12 @@ public class Sorting { int temp; // temporary variable for swapping while (i < j) { - - while (arr[i] <= pivot) { + /* boundary check */ + while (i<=high && arr[i] <= pivot) { i++; } - - while (arr[j] > pivot) { + /*boundary check */ + while (j>=low && arr[j] > pivot) { j--; } //swapping