© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Adetu

❔ Problem with Quick Sort

It seems that it partially sorts it and doesn't finish. I really can't see what is wrong
 void QuickSort(int[] A, int left, int right)
            {
                if (left < right)
                {

                    int pivotIndex = Partition(A, left, right);
                    QuickSort(A, left, pivotIndex - 1);
                    QuickSort(A, pivotIndex + 1, right);
                }


            }

            int Partition(int[] A, int left, int right)
            {

                int p = A[left];
                int i = left + 1;
                for (int j = left + 1; j < right; j++)
                {
                    if (A[j] <= p)
                    {
                        int temp1 = A[j];
                        A[j] = A[i];
                        A[i] = temp1;
                        i += 1;
                    }
                    int temp2 = A[i - 1];
                    A[i - 1] = A[left];
                    A[left] = temp2;
                }
                return i - 1;

            }
 void QuickSort(int[] A, int left, int right)
            {
                if (left < right)
                {

                    int pivotIndex = Partition(A, left, right);
                    QuickSort(A, left, pivotIndex - 1);
                    QuickSort(A, pivotIndex + 1, right);
                }


            }

            int Partition(int[] A, int left, int right)
            {

                int p = A[left];
                int i = left + 1;
                for (int j = left + 1; j < right; j++)
                {
                    if (A[j] <= p)
                    {
                        int temp1 = A[j];
                        A[j] = A[i];
                        A[i] = temp1;
                        i += 1;
                    }
                    int temp2 = A[i - 1];
                    A[i - 1] = A[left];
                    A[left] = temp2;
                }
                return i - 1;

            }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Quick sort question
C#CC# / help
3y ago
Problem with datagridview sorting
C#CC# / help
16mo ago
✅ List.Sort()?
C#CC# / help
15mo ago
Bubble Sort
C#CC# / help
4y ago