Bubble Sort with C Programming

Started by
24 comments, last by Chaozhk 19 years, 10 months ago
i wanted to know can u replace the voi functions with arrays??
Advertisement
quote:Original post by Chaozhk
i wanted to know can u replace the voi functions with arrays??


Sorry but your question is not at all clear. I don''t have a clue what your asking.

I''ll repost iaretony''s solution with source tags so that it won''t get so mangled by the forum, if that doesn''t help you I suggest you try and frame your question more clearly.

#define ARRAY_SIZE 10int foo[ ARRAY_SIZE ];...  for( int i = 0; i < ARRAY_SIZE; i++ )  {    printf("Please enter the %d of %d integers: ", i, ARRAY_SIZE);    scanf( "%d", &foo[i] );  }...
i wanted to ask is there some way to do bubblesorting without using the VOID functions by using arrays? if yes, how to do it?
quote:Original post by Chaozhk
i wanted to ask is there some way to do bubblesorting without using the VOID functions by using arrays? if yes, how to do it?


I''m not entirely sure I''m understanding you. Are you talking about these functions:

void swap(int *a, int *b){    int temp;    temp= *a;    *a= *b;    *b= temp;}void bubbleSort(int x[], int N){    int pass, i;    for (pass=0; pass<=N-2; pass++)        for(i=0; i<=N-pass-2; i++)            if (x[i] > x[i+1])                swap(&x[i], &x[i+1]);}


If so, what''s wrong with the void return type? Why do you need to return anything from them?
yup, i was assigned to use arrays instead of the void functions to make bubble sort... but i don''t know how ...
quote:Original post by Chaozhk
yup, i was assigned to use arrays instead of the void functions to make bubble sort... but i don''t know how ...


You can''t return an int[] or anything like that from a function. You can return a pointer to the start of the array (in this case an int*) but it seems kind a bit pointless to do so - the function will set the values in the original array anyway.

I think you may be misunderstanding the details of your assignment.

This topic is closed to new replies.

Advertisement