SORT2

#include <iostream>
using namespace std;
void SelectionSort(int arr[], int n)
{
  int minindex,temp=0;
  for(int i=0; i<n-1; i++)
  {
    minindex=i;
    for(int j=i+1; j<n; j++)
    {
      if(arr[j]<arr[minindex])
        minindex=j;
    }
    temp=arr[i];
    arr[i]=arr[minindex];
    arr[minindex]=temp;
    if(i==1)
    {
      for(int k=0; k<n; k++)
        cout<<arr[k]<<" ";
    }
  }
}
int main()
{
  int n,arr[20];
  cin>>n;
  for(int i=0; i<n; i++)
    cin>>arr[i];
  SelectionSort(arr,n);
  cout<<"\nSorted Array:";
  for(int i=0; i<n; i++)
    cout<<arr[i]<<" ";
return 0;
}

3 comments:


  1. #include using namespace std;void printSums(int N) { int i,j,sum,k; //i,j control the loops int start,end; //start and end mark their respective points for(i=1;iN) break; if(sum==N) { start=i; end=j; for(k=start;k<=end;k++) cout<>a; printSums(a); return 0;}

    ReplyDelete

SRM ELAB SOLUTUONS   DATA-STRUCTURE                                                                             **IF THE PROGRAM DON...