Thread: sorting of sorts....hehe

  1. #1
    Registered User
    Join Date
    Nov 2001

    Question sorting of sorts....hehe

    OK so ive been given the task of inputting 10 numbers into an array, making sure that there are at least 2 repeating ones,

    for example 1,5,6,6,10,3,5,2,7,8 (6 and 5 repeat)

    Having done this, i am to then write a program that sorts them from lowest to highest and eliminates the unnecessary repeating number, so the program would spit out:

    1,2,3,5,6,7,8,10 (from the above input)

    I havent the slightest clue where to even begin, because the fact that we have to eliminate repeating numbers completley voids the way i was taught to sort arrays.
    Any help would be much appreciated,

  2. #2
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    well, first create your array (if i'm wrong with any of this, correct me somebdoy)

    // create the array and set the numbers to it
    int nArray[9] = {1,5,6,6,10,3,5,2,7,8}; // I think this is how

    then just use a while or for loop to display the right numbers

  3. #3
    But those numbers can change, remember?

    But this one should be easy, try this: Sort the array (you obviously know how?), and then use a loop to go through each element of the array and print out that element, except if the element before the one to be printed, equals to this one. ie:

    if (Array[Element - 1] != Array[Element]) printf("%d", Array[Element]);

    You could also add a check to see that Element > 0 to see if you need to check the element before, to avoid any odd errors or such.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Simple Sorts Confuse ME =/
    By otchster in forum C Programming
    Replies: 5
    Last Post: 12-03-2005, 02:02 PM
  3. sorting structure members using pointers
    By robstr12 in forum C Programming
    Replies: 5
    Last Post: 07-25-2005, 05:50 PM
  4. selection sorting using going-down and going-up recursion
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 02:29 PM
  5. Still Needing Help : selection sorting
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 10-14-2001, 08:41 PM