0% found this document useful (0 votes)
35 views2 pages

Programme For Selection Sort in Array

This C++ program uses selection sort to sort an array of integers. It prompts the user to enter the number of array elements, reads the elements into an array, and calls the selection sort function. The selection sort function iterates through the array, finds the smallest remaining element, and swaps it into the current position to sort the array. After each pass, it prints the current sorted array.

Uploaded by

Suraj Kundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views2 pages

Programme For Selection Sort in Array

This C++ program uses selection sort to sort an array of integers. It prompts the user to enter the number of array elements, reads the elements into an array, and calls the selection sort function. The selection sort function iterates through the array, finds the smallest remaining element, and swaps it into the current position to sort the array. After each pass, it prints the current sorted array.

Uploaded by

Suraj Kundu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

20.

PROGRAMME FOR SELECTION SORT


IN ARRAY
#include<iostream.h>
#include<conio.h>
void SelectionSort(int a[],int n);
void main()
{
int A[20],N;
clrscr();
cout<<"Enter umber of elements: ";
cin>>N;
cout<<"\nEnter the elements: ";
for(int i=0;i<N;i++)
cin>>A[i];
SelectionSort(A,N);
getch();
}
void SelectionSort(int a[],int n)
{
int i,small,pos,temp;
for(i=0;i<n;i++)
{
small=a[i];
pos=i;
for(int j=i+1;j<n;j++)
{
if(a[j]<small)
{
small=a[j];
pos=j;
}
}
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
cout<<"\nAfter pass"<<i+1<<endl;
for(j=0;j<n;j++)
cout<<a[j]<<"\t";
}
1
}

You might also like