Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main(){
- cout<<"Selection Sort\n\n";
- cout<<"Input banyak data : ";
- int n,pos;
- cin>>n;
- int data[n];
- cout<<"Input data : \n\n";
- for(int i=0; i<n; i++){
- cout<<"Data-"<<i+1<<" : ";
- cin>>data[i];
- }
- //===========Selection Sort
- for(int i=0; i<n-1; i++){
- pos = i;
- for(int j=i+1; j<n; j++){
- if(data[j]<data[pos]) //Ascending
- pos =j;
- }
- if(pos != i)
- swap(data[pos],data[i]);
- }
- //=================
- cout<<"\nSorted Data\n";
- for(int i=0; i<n; i++){
- cout<<data[i]<<" ";
- }
- cout<<"\n";
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement