Thread: simple sorting problem

  1. #16
    Registered User MacNilly's Avatar
    Join Date
    Oct 2005
    Location
    CA, USA
    Posts
    466
    Someone trying to implement bubble sort with no knowledge of for loops or basic C operators? I think you're way ahead of yourself. Go back and learn some basic arrays, for loops, and C operators. Then try to implement a bubble sort. Make sure you can do it on paper first.

    Not trying to be mean, but that is the best way, judging by the errors I saw.

    Get rid of all the functions and other crap you've got going on that are wrong and just use a main function with one array, and a two loops and a simple swap (no function calling swap). If you can do that, and get it to work, add one small thing to it, TEST IT, if it works, add another, repeat. Modularize code that has been testing into functions. This is called programming. You can't have 100 things going on that have errors and expect to correct it. Start from the very basics and build up, slowly, testing everything.

    If you got this far, I'll give you a hint.

    Make a function called printarray that takes 2 parameters a pointer to the type of elements in your array, in this case, integers, and a number of elements. Use a for loop to print each value in the array to the screen in a readable format (your gonna be reading this stuff not anyone else). Then instead of cluttering up your code with a thousand for loops, just call printarray(thisarray, thisarraysize). Makes it easier on ya man.
    Last edited by MacNilly; 08-14-2007 at 11:44 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 06-11-2009, 11:27 AM
  2. Fairly simple problem
    By fatdunky in forum C Programming
    Replies: 1
    Last Post: 11-14-2005, 11:34 PM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  5. Replies: 5
    Last Post: 12-03-2003, 05:47 PM