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

  • SEARCH
  • Home
  • 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 6539819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:54:16+00:00 2026-05-25T10:54:16+00:00

i am trying to implement following algorithm: suppose there is array a[3][3], my aim

  • 0

i am trying to implement following algorithm:
suppose there is array a[3][3], my aim is choose some pivot element,for example a[1][1] and make partition such that, all element less then a[1][1] must be on left side and above the pivot element, and all greater element on the right side and below pivot element. for example consider following matrix:

6 4 3
8 5 2
1 7 9

one of the possible partition of it is

3 4 6
2 5 7
1 8 9

as you see all less element are on the left side and above the pivot called 4. and others on the right side and below the pivot as 8.
here is my code

#include <iostream>
using namespace std;
int main(){
  int a[3][3];
  for (int i=0;i<3;i++) {
    for (int j=0;j<3;j++){
      cin>>a[i][j];
    }
  }

  int i=0;
  int j=0;
  int n=2;
  int m=2;
  int pivot=a[1][1];

  while(  m>i && n>j) {
    while(a[m][n]>pivot)  --m;--n;
    while( a[i][j]<pivot) ++i;++j;

    int t=a[i][j];
    a[i][j]=a[m][n];
    a[m][n]=t;
  }

  for (int i=0;i<3;i++){
    for (int j=0;j<3;j++){
      cout<<a[i][j]<<"  ";
    }
    cout<<endl;
  }
  return 0;
}

but when i enter matrix above mentioned i got wrong result

6  5  3
8  4  2
1  7  9

please help me

  • 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-25T10:54:17+00:00Added an answer on May 25, 2026 at 10:54 am

    Your problem as stated does not have a general solution. Specifically, there is no guarantee that all of the values less than the initial pivot value will fit to the left of the initial pivot point, nor that all of the values greater than the initial value will fit to the right of the initial pivot point.

    You need to relax your requirements so that either the pivot value or the pivot location is allowed to change during the execution of the algorithm.

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

Sidebar

Related Questions

I am trying to implement Quick Sort algorithm. Following code works for unique elements
I trying to implement synchronization algorithm in C#, without success. Why isn't the following
I've been trying to implement the Luhn algorithm in Ruby. I've been following these
I'm trying to implement Peterson's algorithm in Java, and have created the following for
Well am referring the following paper and trying to implement the algorithm as given
I'm trying to implement the following mod_rewrite rule: host.com/developer/ => host.com/developer/index.py host.com/developer/branchX => host.com/developer/index.py?branch=branchX
I'm trying to implement routing such as the following: posts/535434/This-is-a-post-title posts/tagged/tags+here // Matches {controller}/{action}/{id}
I'm trying to implement XOR in javascript in the following way: // XOR validation
I'm trying to implement my own GenericIdentity implementation but keep receiving the following error
I'm trying to implement http://github.com/bengottlieb/Twitter-OAuth-iPhone/tree/master into my code. I'm following the Demo provided and

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.