Sorting question

This is a discussion on Sorting question within the C Programming forums, part of the General Programming Boards category; I have a question about sorting. I'm starting a homework project and have to write a program that will compare ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58

    Sorting question

    I have a question about sorting. I'm starting a homework project and have to write a program that will compare insertion, selection, and bubble sort while outputting the number of swaps and comparisons of array of 10, 100, and 1000. I in the process of writing the functions for each sort. My question is: do I have to write a seperate function for each array size? example bblSortTen(), bblSortHundred(), bblSortThousand() or can I use 1 function bbleSort to do the 3 different size arrays. I've been trying to think through it but I can't think of a way to get all 3 arrays in 1 function. Any advice would be greatly appreciated.

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    50
    u can do that if you pass the whole array (obviously as pointer) as well as its size in the calling function.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You want to write 3 functions,besides main . Each function will be one type of sort, and will take the array (from main(), and will include (in a parameter), the number that the sorting should stop at. Your main() will have the array, and will assign the values to be sorted (perhaps using a rand() selector for that).

    Each sorting function will print out it's spec's for the sort it has completed, or you can call a single function just for that, and pass it the data it needs. Saves a bit of code that way.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Location
    Baltimore Md. USA
    Posts
    58
    Awesome, thanks. I was hoping there would be a way to avoid too many functions. That helps a lot.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. List Sorting Question
    By Polystyrene in forum C++ Programming
    Replies: 16
    Last Post: 08-28-2010, 03:04 PM
  2. sorting question
    By archriku in forum C Programming
    Replies: 47
    Last Post: 03-26-2009, 01:28 PM
  3. Sorting Question
    By Rkukulski in forum C++ Programming
    Replies: 13
    Last Post: 04-28-2008, 01:37 PM
  4. sorting question
    By panfilero in forum C Programming
    Replies: 5
    Last Post: 11-22-2005, 08:16 AM
  5. A question about sorting..
    By NightWalker in forum C Programming
    Replies: 2
    Last Post: 11-12-2003, 09:24 AM

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