Help implementing bubble sort

This is a discussion on Help implementing bubble sort within the C++ Programming forums, part of the General Programming Boards category; This is something that I have been working on but when I compile it I get the can error that ...

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    22

    Help implementing bubble sort

    This is something that I have been working on but when I compile it I get the can error that says for the line
    Could anyone tell me how to fix this?
    Last edited by c++prog; 11-06-2009 at 11:30 PM.

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Your prototype is wrong:
    Code:
    void bubblesort(double, int);
    Here's your implementation:
    Code:
    void bubblesort(double *arraya,int length)//Bubble sort function
    See the difference?

  3. #3
    Registered User
    Join Date
    Feb 2008
    Posts
    22
    Quote Originally Posted by rags_to_riches View Post
    Your prototype is wrong:
    Code:
    void bubblesort(double, int);
    Here's your implementation:
    Code:
    void bubblesort(double *arraya,int length)//Bubble sort function
    See the difference?
    No, is it because I'm using a pointer? Because even using the bubblesort function that I have commented out I still get the same error and I am not using a pointer in that one.

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    22
    I changed the function header to void bubblesort(double *arraya, int length); and now it will compile but it won't sort the array.

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    Well for one that's not bubblesort. Bubblesort does not use both for loop variables in the inner loop. Instead it uses i-1 or i+1 to compare element i to its neighbour, which causes items to appear to bubble up through the array, and more crucially BubbleSort is stable, whereas that is not.
    What you have is also common, but is a different algorithm (apart from the fact that it's slightly broken as well).

    If you really mean to implement bubblesort then the best thing you can do is to go and look it up on wikipedia or elsewhere.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Registered User
    Join Date
    Feb 2008
    Posts
    22
    Nevermind, I've figured it out by looking up information online and editing the function. Thanks to everyone.
    Last edited by c++prog; 11-06-2009 at 11:14 PM.

  7. #7
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,648
    Classy, removing all your code.

  8. #8
    Registered User
    Join Date
    Feb 2008
    Posts
    22
    The reason I removed all my code was because this was for an assignment and I didn't want anyone to cheat off of it. If you want to see what I have now I can private message it to you.
    John 3:16 For God so loved the world that He gave His only begotten Son, that whoever believes in Him should not perish but have everlasting life.

  9. #9
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,625
    No one cares about your particular implementation of bubble sort dude, especially since it doesn't even work. And it's not that "we want to see what you have" it's just that you've removed all of the discussion's context.

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    This is why I sometimes quote the entire original post. Next time I'm doing that.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. bubble sort not working... wats d prob?
    By Huskar in forum C Programming
    Replies: 8
    Last Post: 03-31-2009, 11:59 PM
  2. My bubble sort only sorts once
    By Muller in forum C Programming
    Replies: 8
    Last Post: 03-27-2009, 04:36 PM
  3. help with debug (bubble sort algorithm)
    By lbraglia in forum C Programming
    Replies: 5
    Last Post: 10-19-2007, 05:24 PM
  4. Bubble Sort... which type?
    By gflores in forum C++ Programming
    Replies: 8
    Last Post: 08-15-2004, 04:48 AM
  5. Bubble Sort, Qucik Sort
    By insomniak in forum C Programming
    Replies: 2
    Last Post: 03-15-2003, 03:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21