Selection sort in data structures and algorithms in c

 #include<stdio.h>




void accetp(int *aint n)
  {
// 
    int i;
    for(i=0;i<n;i++){
        printf("Enter the %d  element :-",i+1);
    scanf("%d",&a[i]);
    }
  }


void printarray(int *aint n)
{
//          
            int i;
            for(i=0;i<n;i++)
            {
            printf("%d\t",a[i]);
            }
        printf("\n");
        }


void selectionSort(int *aint n){
    int indexOfMintemp;
    printf("Running Selection sort...\n");
    for (int i = 0i < n-1i++)
    {
        indexOfMin = i;
        for (int j = i+1j < nj++)
        {
            if(a[j] < a[indexOfMin]){
                indexOfMin = j;
            }
        }
        // Swap A[i] and A[indexOfMin]
        temp = a[i];
        a[i] = a[indexOfMin];
        a[indexOfMin] = temp;
    }
}

void main()
{
        
            int a[20],i,n;
            printf("how many numbers :-\n");
            scanf("%d",&n);

            printf("Enter the unsorted elements :-\n");
            accetp(a,n);
            selectionSort(a,n);
            printf("print the sorted output:-");
            printarray(a,n);    

                
}
        










Post a Comment

0 Comments