I think this will work. # include "stdio.h"
void my_print(int *,int); void swap(int &a , int&b) { a = a + b; b = a - b; a = a - b; } void sort(int* array, int SIZE, int i, int j) { while(i<j) { my_print(array,SIZE); if(array[i] <= array[j]) i++; if(array[j] < array[i]) { swap(array[i] , array[j]); i++; int temp = j; while(temp< (SIZE-1) && (array[temp] > array[temp+1]) ) { swap(array[temp] , array[temp + 1]); temp++; } } } } void my_print(int * array, int SIZE) { printf("\n"); int i = 0; for(; i < SIZE ; i++) printf("%d, ",array[i]); printf("\n"); } int main() { int array1[8] = {1,3,6,7,4,5,6,8}; int array2[10] = {1,2,3,5,6,7,4,8,9,10}; int array3[10] = {10,20,30,40,50,23,27,40}; //sort(array1,8,0,4); //sort(array2,10,0,6); sort(array3,8,0,5); //my_print(array1,8); //my_print(array2,10); my_print(array3,8); return 0; } On Mon, Jul 12, 2010 at 10:20 AM, Abhishek Kumar Singh < iiita2007...@gmail.com> wrote: > @souravsain > > for input {10,20,30,40,50,23,27}; > ur output is coming 10, 20, 23, 27, 40, 30, 50, > which not SORTED array..... > > On Jul 10, 6:19 pm, souravsain <souravs...@gmail.com> wrote: > > @Jitendra > > > > I have run the code with input given by you and found that it works > > well. > > > > Please have a look athttp://codepad.org/iMBTwAL7 > > > > Appriciate the effort taken by you to analyze the solution and do let > > me know if you still do not agree with the code. > > > > Regards, > > Sourav > > > > On Jul 8, 9:03 pm, Jitendra Kushwaha <jitendra.th...@gmail.com> wrote: > > > > > > > > > @souravsain > > > Consider your algo for the case > > > int arr[] = {10,20,30,40,50,23,27}; > > > > > everytime when you increment the j you are missing on element i.e j-1 > for > > > further comparison > > > > > -- > > > Regards > > > Jitendra Kushwaha > > > MNNIT, Allahabad > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.