Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Insertion Sort
- #include <stdio.h>
- int total, data[10];
- int a, b;
- void input()
- {
- scanf("%d",&total);
- for(a=0;a<total;a++)
- {
- scanf("%d",&data[a]);
- }
- }
- void sort()
- {
- int temp,key,i;
- for(a=0;a<total;a++)
- {
- key=data[a];
- i=a-1;
- while(i>=0 && data[i]>key)
- {
- data[i+1]=data[i];
- i=i-1;
- data[i+1]=key;
- }
- }
- }
- void view()
- {
- for(a=0;a<total;a++)
- {
- printf("%d",data[a]);
- }
- printf("\n");
- }
- int main()
- {
- input();
- sort();
- view();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement