Selection sort step by step animation, for the programming beginners to get a better understanding of selection sort algorithm.(Click snail button to start animation and click it again to go back to the first page)
Cost: O(n^2)
Worst case: O(n^2)
Best case: O(n)
Selection sort code in C++:
void SelectionSort(int a[],int size)
{
for(int
i=0;i<size-1;i++)
{
int min=i;
for(int j=i+1;j<size;j++)
{
if(a[j]<a[min])
{
min=j;
}
}
if
(min > i)
swap(a[i],a[min]);
}
}
int main()
{
int a[]={25,49,8,25,21,16,32};
SelectionSort(a,7);
}
Heap Sort
Binary Search
Merge Sort
Quick Sort
Bubble Sort
No comments:
Post a Comment