Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:21:44+00:00 2026-05-29T04:21:44+00:00

Why this code gives me wrong ? In Quick sort , I have picked

  • 0

Why this code gives me wrong ? In Quick sort , I have picked up the first element as pivot:

I have traced that on paper,nothing is wrong.

    private void QuickSort(ref int [] S ,int l,int h)
    {
        //partioning
        int pivot_index = l;
        int j = 0;
        int temp = 0;
        for(int i=l+1;i<=h;i++)
            if (S[pivot_index] > S[i])
            {
                j++;
                temp = S[i];
                S[i] = S[j];
                S[j] = temp;
            }
        pivot_index = j;
        temp = S[l];
        S[l] = S[j];
        S[j] = temp;
        //end partioning

        if (l < h && pivot_index>l && pivot_index<h)
        {
            QuickSort(ref S, l, pivot_index - 1);
            QuickSort(ref S, pivot_index + 1, h);
        }
    }

here is my main :

        int[] List = get_input(textBox1.Text, ref n);
        //
        QuickSort(ref List, 0, n-1);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:21:48+00:00Added an answer on May 29, 2026 at 4:21 am

    Your function is apparently supposed to sort [l, h] range in the array, yet for some reason you are swapping element number i with element number j. The latter (j) is out of [l, h] range (it is always initially 0 and then it becomes 1, 2, 3 and so on). What are you trying to do by this? Why are you swapping your elements to some totally unrelated remote location out of your sorting range?

    In other words this does not even remotely look like a QuickSort-style sorting algorithm to me. Your unexplainable manipulations with j is one reason why your implementation cannot really sort anything.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code like this below, which gives me a $link that equals
I already have this code but it gives me the wrong result. private void
I have this piece of code that gives me this when executed: Microsoft VBScript
I have this in my code: SelectList(blah, blah, blah, cu.Customer.CustomerID.ToString()) It gives a error
Please I have this code which gives me many errors: //Neuron.h File #ifndef Neuron_h
I have this code which gives me the below output in firebug, so according
Apparently, this code gives me error at the last line cvCvtColor(), what is wrong?
This code gives me an empty result. I expect it to print out the
I am not sure why this code (gives stackoverflow at runtime) compiles: import java.io.*;
This piece of code gives a syntax error at the colon of elif process.loop(i,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.