#include<iostream.h> #include<conio.h> void main() { clrscr(); int a[100],i,n,p,ptr,temp; cout<<"\n***PROGRAM INSERTION SORT*** \n\n"; cout<<"Masukkan Element : "; cin>>n; cout<<"\nElementnya : \n"; for(i=1;i<=n;i++) { cin>>a[i]; } a[0]=0; for(p=2;p<=n;p++) { temp=a[p]; ptr=p-1; while(temp<a[ptr]) { a[ptr+1]=a[ptr]; ptr--; } a[ptr+1]=temp; } cout<<"\nSetelah di Urutkan : \n"; for(i=1;i<=n;i++) { cout<<a[i]<<endl; } getch(); }
10:08 PM |
Category: |
0
comments
Comments (0)