Thread: What kind of sorting Algorithm has been used here?

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    4

    What kind of sorting Algorithm has been used here?

    Code:
    #include <stdio.h>
    #define MAX_SIZE 100    // Maximum array size
    
    int main()
    {
        int arr[MAX_SIZE];
        int size;
        int i, j, temp;
    
        /* Input size of array */
        printf("Enter size of array: ");
        scanf("%d", &size);
    
        /* Input elements in array */
        printf("Enter elements in array: ");
        for(i=0; i<size; i++)
        {
            scanf("%d", &arr[i]);
        }
    
        for(i=0; i<size; i++)
        {
            /* 
             * Place currently selected element array[i]
             * to its correct place.
             */
            for(j=i+1; j<size; j++)
            {
                /* 
                 * Swap if currently selected array element
                 * is not at its correct position.
                 */
                if(arr[i] > arr[j])
                {
                    temp     = arr[i];
                    arr[i] = arr[j];
                    arr[j] = temp;
                }
            }
        }
    
        /* Print the sorted array */
        printf("\nElements of array in ascending order: ");
        for(i=0; i<size; i++)
        {
            printf("%d\t", arr[i]);
        }
    
        return 0;
    }
    Last edited by Salem; 06-26-2018 at 09:54 AM. Reason: Added code tags around dog-food

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    4
    I have already read there, can't find answer there. I want to know only name of sorting technique used here.

  4. #4
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    It looks like a badly-implemented selection sort.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What kind of algorithm do I need to apply for this ?
    By manasij7479 in forum Tech Board
    Replies: 7
    Last Post: 12-14-2013, 10:46 AM
  2. what's problem with this kind of sorting ??
    By rajarshi in forum C Programming
    Replies: 6
    Last Post: 11-23-2011, 12:18 PM
  3. Sorting Algorithm Help
    By cjwenigma in forum C++ Programming
    Replies: 8
    Last Post: 11-02-2007, 02:04 PM
  4. sorting algorithm
    By RazielX in forum C Programming
    Replies: 4
    Last Post: 05-04-2004, 06:20 PM
  5. 'Sorting' algorithm
    By Dual-Catfish in forum C++ Programming
    Replies: 3
    Last Post: 11-03-2001, 02:09 AM

Tags for this Thread