bubble sort

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimhakans
    New Member
    • Sep 2007
    • 41

    bubble sort

    hello there,
    i have very little concept of bubble sort. This code here is not working can u explain Why?
    Code:
    #include<stdio.h>
    main()
    {
    int array[4]={60,88,33,40};
    int j,i;
    for(i=0;i<4;i++)
    {
    for(j=i+1;j<4;j++)
    if(array[i]>array[j])
    swap(&array[i],&array[j]);
    }
    printf("%d",array[i]);
    }
    Can anyone explain me why memory locator(&) is used in swap(line10).
    Thanks in advance.
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Where's your swap implemented? After I did some touch-ups (like making it int main() ), that's the only thing my compiler complained about.

    Comment

    • jimhakans
      New Member
      • Sep 2007
      • 41

      #3
      Originally posted by sicarie
      Where's your swap implemented? After I did some touch-ups (like making it int main() ), that's the only thing my compiler complained about.
      My compiler is saying undefined function "swap" in function main().
      and i dont understand why there is locator in line 10.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by jimhakans
        My compiler is saying undefined function "swap" in function main().
        and i dont understand why there is locator in line 10.
        That's why I asked where your implementation of swap() was. You don't have one. You need to create one (or include a library with a swap()) to get rid of that error.

        The & symbol is the reference - it gets the address of the variable, not the value, so that you are modifying the variable directly.

        Comment

        Working...