Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream.h>
- #include<conio.h>
- int data[10],data2[10];
- int n;
- void tukar(int a, int b)
- {
- int t;
- t=data[b];
- data[b]=data[a];
- data[a]=t;
- }
- void input()
- {
- cout<<"Masukkan jumlah data = ";
- cin>>n;
- for(int i=0;i<n;i++)
- {
- cout<<"Masukkan data ke - "<<(i+1)<<" = " ;
- cin>>data[i];
- data2[i]=data[i];
- }
- }
- void selection_sort()
- {
- int pos,i,j;
- for(i=0;i<n-1;i++)
- {
- pos=i;
- for(j=i+1;j<n;j++)
- {
- if(data[j]<data[pos])pos=j;
- }
- if(pos!=i) tukar(pos,i);
- }
- cout<<"selection sort selesai !"<<endl;
- cout<<"Data : "<<endl;
- for(int i=0;i<n;i++)
- {
- cout<<data[i]<<" ";
- }
- cout<<endl;
- }
- void main()
- {
- int pil;
- clrscr();
- do
- {
- cout<<endl;
- cout<<"1. Input Data"<<endl;
- cout<<"2. Selection Sort"<<endl;
- cout<<"3. Exit"<<endl;
- cout<<"Masukkan Pilihan anda = ";
- cin>>pil;
- switch(pil)
- {
- case 1: input();break;
- case 2: selection_sort();break;
- }
- getch();
- }
- while(pil!=3);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement