# Sorting using Recursion function

• 02-15-2003
moemen ahmed
Sorting using Recursion function
Hi , i wrote this code ,which sort an array of floats using a recursion function (available in the code to sort just some members of the array), i finished it just like you can see, and its working well, but sometimes it turns the largest no in the array into very small no like (2.15154e-41) !!!!!!!!!!!!!!!! , try it out and tell me what do u think !!!! [try numbers in thousands ]

Code:

```#include <stdio.h> #include <iostream> #include <conio.h> void quicksort(int a[],int i, int j) {   int temp =0;   for (int count=i;count<j+1;count++)   {     for (int count2=count+1;count2<j+1;count2++)     {       if (a[count]>a[count2])       {       temp=a[count];       a[count]=a[count2];       a[count2]=temp;       }     }   } } int main(int argc, char *argv[]) {   int marks[10];   int no;   cout<<"How many marks you have ? (MAX 10)  ";   cin>>no;   for (int g=0;g<no;g++)   {     cout<<endl<<"enter mark no "<< (g+1)<<"  " ;     cin>>marks[g];   }   int s,f;   cout<<"\nEnter the initial index you want to begin the sort from ";   cin>>s;   cout<<"\nEnter the finish index you want to stop the sort at ";   cin>>f;   int *p=&marks[0];   quicksort(p,s-1,f-1);   for (int l=0;l<no;l++)   {     cout<<"  "<<marks[l]<<"  ";   }   getche();   return 0; }```
I hope someone has the answer :) thanks
• 02-15-2003
PJYelton
I'm confused, how is this recursion? I don't see anywhere where the sort function calls itself again.

Also, what values do you enter that mess up exactly?
• 02-15-2003
moemen ahmed
im so sorry , i posted the another code i wrote for the same thing
im a dummy :(

Code:

```#include <stdio.h> #include <conio.h> #include <iostream> void quicksort(float a[],int i,int j) {   bool ok=true;   int temp=0;   for (int count1=i;count1<j+1;count1++)   {     if (a[count1]>a[count1+1])     {       ok=false;     }   }   if (ok) {return ;};   for (int count2=i;count2<j+1;count2++)   {     if (a[count2]>a[count2+1])     {       temp=a[count2];       a[count2]=a[count2+1];       a[count2+1]=temp;     }   }   float *pp=&a[0];   quicksort(pp,i,j); } int main(int argc, char *argv[]) {   float marks[10];   int no;   cout<<"How many marks you have ? (MAX 10)  ";   cin>>no;   for (int g=0;g<no;g++)   {     cout<<endl<<"enter mark no "<< (g+1)<<"  " ;     cin>>marks[g];   }   int s,f;   cout<<"\nEnter the initial index you want to begin the sort from ";   cin>>s;   cout<<"\nEnter the finish index you want to stop the sort at ";   cin>>f;   float *p=&marks[0];   quicksort(p,s-1,f-1);   for (int l=0;l<no;l++)   {     cout<<"  "<<marks[l]<<"  ";   }   getche();   return 0; }```
thats my code
try to enter 5 no for examples (2,300,123,2000,4100)

sorry for this mistake
and thanks PJYelton for the reply :)
• 02-15-2003
alpha
I don't really see how it turns numbers into small numbers. What numbers are you plugging in that it does this?

edit: I haven't tried numbers in the millions or higher, just too slow due to the fact that it is recursion.
• 02-15-2003
moemen ahmed
these no causes me the problem:(10 no)
65 32 125 1 266 484444 656 2 154 1

after all, thanks for caring and for replying all :)
• 02-15-2003
alpha
I don't really see any probs here, tested with 5 numbers, 10 numbers, and 3. Index from 0 to (n - 1). Sorry.
• 02-15-2003
Snoop
I dont really see the problem either.. sorry for not been any help