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

Join 136,494 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,715 people online right now. Registration is fast and FREE... Join Now!




Quick sort operation

 
Reply to this topicStart new topic

Quick sort operation, someone help for my coding pls....

mohdsyukri
6 Mar, 2008 - 09:21 AM
Post #1

New D.I.C Head
*

Joined: 24 Feb, 2008
Posts: 5

actually i was doing the exercise for ascending number with the most fast way reading so....im trying to do this coding...call quick sort and i got an error...

can someone help me pls...................!!!!


CODE
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>

void quick1(char *test,int lolimit,int hilimit);
void quikSort(char *test,int lolimit,int hilimit);
void swap(char *test,char *b);

void main()
{ clrscr();
  char test[80];
  struct LLnode;
  char choice;
  int lolimit,hilimit;
  clrscr();
  printf("String to sort>> ");
  scanf("%d",&test);

  printf("sort by...");
  printf("\t[Q]Quick1");
  printf("\t[S]QuikSort");
  printf("choice>>");
  
  printf("%s (input string)\n",test);
  switch(choice){
        case 1 :
                 quick1(test,lolimit,hilimit);
                 puts(test);
                 break;
        case 2 :
                 quikSort(test,lolimit,hilimit);
                 puts(test);
                 break;
}
  getch();
}

void swap(char *test,char *b){
  char tmp=*test;
  *b=tmp;
  return;
  }

void quick1(char *test,int lolimit,int hilimit){
    int recurselevel;
    int jbig=lolimit+1;
    int jsmall=hilimit;
    char pivot=test[(jbig+jsmall)/2];
        printf("%s lolimit=%d hilimit=%d pivot=%c recurselevel-%d\n",test,lolimit,hilimit,pivot,recurselevel);
    if(hilimit-lolimit<=0);
    return;
    if(hilimit-lolimit==1){
           if(test[lolimit]>test[hilimit])
       swap(&test[lolimit],&test[hilimit]);
       return;
       swap(&test[lolimit],&test[(jbig+jsmall)/2]);
    do{
        while((jbig<=jsmall)&&(test[jbig]<pivot))
        jbig++;

        while((jsmall>=jbig)&&(test[jsmall]>=pivot))
        jsmall--;
    if(jbig<jsmall)swap(&(test[jbig]),&(test[jsmall]));

      }
      while (jbig<jsmall);
        swap(&test[lolimit],&test[jbig-1]);
        recurselevel++;
           quick1(test, lolimit, jbig-2);
           quick1(test,jbig,hilimit);
         recurselevel--;
  return;
  }

void quikSort(char *test,int lolimit,int hilimit){
    int lo = lolimit;
        int hi = hilimit;
      char pivot =a[(lolimit+hihimit)/2];
       printf("%s loLimit=%d hiLimit=%d pivot=%c recurseLevel=%d\n",test,lolimit,hilimit,pivot,++recurselevel);
            
     while (lo<=hi){

     while ((lo<hilimit) && (a[lo]<pivot))lo++;
     while ((hi>lolimit) && (a[hi]>pivot))hi--;
    if (lo<=hi){
       swap(&a[lo],&test[hi]);
       lo++;
       hi--;
       }
      }
    if (lolimit<hi)quikSort(a,lolimit,hi);
      if (lo<hilimit)quikSort(test,lo,hilimit);
      recurselevel--;
   return;
}
  }



Attached thumbnail(s)
Attached Image
User is offlineProfile CardPM
+Quote Post

lockdown
RE: Quick Sort Operation
6 Mar, 2008 - 12:13 PM
Post #2

D.I.C Regular
Group Icon

Joined: 29 Sep, 2007
Posts: 376



Thanked: 1 times
Expert In: PC, Support

My Contributions
What is the error you are getting? It will make debugging the code much easier for one of us.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/2/08 07:57PM

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