Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 135,947 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,739 people online right now. Registration is fast and FREE... Join Now!




quicksort

 
Reply to this topicStart new topic

quicksort, guyz can any 1 tell me wat is wrong with my quicksort code??

lilseraphin
18 May, 2008 - 01:53 PM
Post #1

New D.I.C Head
*

Joined: 9 May, 2008
Posts: 2

cpp
#include "stdafx.h"
#include <iostream>
#include <string>
#define size 6
using namespace std;
void Quicksort (string [], int, int);
int _tmain(int argc, _TCHAR* argv[])
{string Arr[size];
cout<<"Enter the array"<<endl;
for (int b=0; b<size; b++)
cin>>Arr[b];
Quicksort(Arr,0, size-1);
for (int a=0; a<size; a++)
cout<<Arr[a]<<endl;
return 0;
}
void Quicksort (string Ar[], int low, int high)
{
int i=low, j=high;
string pivot=Ar[low];
while (i<j)
{
while (Ar[i]<pivot)
i++;
while (Ar[j]>pivot)
j--;
if (i<=j)
{
swap (Ar[i],Ar[j]);
i++;
}
if (low<j)
Quicksort (Ar,low,j);
if (i>high)
Quicksort (Ar,high,i);
}

} //Plz guyz some1 tell me wat is wrong with this code, my email is lilseraphin@hotmail.com

User is offlineProfile CardPM
+Quote Post

KYA
RE: Quicksort
18 May, 2008 - 03:49 PM
Post #2

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,735



Thanked: 89 times
Dream Kudos: 1200
My Contributions
You'll get better responses if you say what errors there are and what the program is trying to achieve.
User is online!Profile CardPM
+Quote Post

skater_00
RE: Quicksort
18 May, 2008 - 04:35 PM
Post #3

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
There are no errors. The sorting algorithm is just incorrect.

By the way: you enter 6 numbers and the program prints those 6 numbers again, but sorted in the correct order.

This post has been edited by skater_00: 18 May, 2008 - 04:39 PM
User is offlineProfile CardPM
+Quote Post

KYA
RE: Quicksort
18 May, 2008 - 08:34 PM
Post #4

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,735



Thanked: 89 times
Dream Kudos: 1200
My Contributions
Truth be told I won't even try to compile it unless some description is added, so i have an idea of what to look for. Code tags are also nice
User is online!Profile CardPM
+Quote Post

skater_00
RE: Quicksort
19 May, 2008 - 01:49 AM
Post #5

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
KYA, I guess it's pretty obvious what "quicksort" is going to do... I thought the policy was providing code. I see code...
User is offlineProfile CardPM
+Quote Post

KYA
RE: Quicksort
19 May, 2008 - 01:50 AM
Post #6

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,735



Thanked: 89 times
Dream Kudos: 1200
My Contributions
I agree. However, "What's wrong? Please tell me" is ambiguous as hell.

It's like going to the doctor and saying you feel bad, but nothing else.

This post has been edited by KYA: 19 May, 2008 - 01:53 AM
User is online!Profile CardPM
+Quote Post

skater_00
RE: Quicksort
19 May, 2008 - 01:54 AM
Post #7

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
True, but why is he asking that? Because the compiler gives him 0 errors or warnings and still his quicksort won't work. Anyway, enough BS, your choice. =)

This post has been edited by skater_00: 19 May, 2008 - 01:55 AM
User is offlineProfile CardPM
+Quote Post

KYA
RE: Quicksort
19 May, 2008 - 02:01 AM
Post #8

#include <nerd.h>
Group Icon

Joined: 14 Sep, 2007
Posts: 4,735



Thanked: 89 times
Dream Kudos: 1200
My Contributions
He didn't say it gave him zero errors. Which was my original statement. You'll see a lot of posters that post code with syntax errors and the like. If it is not explicitly stated, then i am skeptical. Assuming you read what you wrote all you said was that the algorithm isn't working, but then jumping in my face about me asking what the problem is.

Let's assume he knows his algorithm is wrong and that's why he posted for help. The pot is calling the kettle black.

Sorry for the thread derailment.
User is online!Profile CardPM
+Quote Post

skater_00
RE: Quicksort
19 May, 2008 - 02:46 AM
Post #9

D.I.C Head
Group Icon

Joined: 30 Apr, 2008
Posts: 173



Thanked: 4 times
Dream Kudos: 50
My Contributions
You don't need to apologize, KYA. I agree that I was wrong, sorry.

Anyways, back on topic.

Lilseraphin, I have never really used quicksort before so I'm not too familiar with it. Try to look for "quicksort" or "quicksort algorithm" on a search engine to see how the quicksorting algorithm works and so you can edit it where necessary.
User is offlineProfile CardPM
+Quote Post

gabehabe
RE: Quicksort
19 May, 2008 - 03:10 AM
Post #10

Donkey DIC
Group Icon

Joined: 6 Feb, 2008
Posts: 5,514



Thanked: 96 times
Dream Kudos: 2650
Expert In: ruling the world.

My Contributions
A Wikipedia article on the quick sort algorithm

smile.gif
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/1/08 08:52AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month