Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<limits.h>
- #include<iostream>
- int a[1000];
- int n ;
- void input();
- void output();
- void sorting(int , int);
- int main()
- {
- input();
- sorting(1,n);
- output();
- }
- void input()
- {
- printf("How many numbers:");
- scanf("%d",&n);
- printf("Insert numbers:\n");
- int i;
- for(i=1 ; i<=n ; i++)
- {
- scanf("%d",&a[i]);
- }
- }
- void output()
- {
- printf("\nSorted array:");
- for(int i=1 ; i<=n ; i++)
- {
- printf("%d ",a[i]);
- }
- }
- void sorting(int f , int l)
- {
- if(f < l)
- {
- int i=f+1 ;
- while(a[i] < a[f])
- i++;
- int j=l;
- while(a[j]>a[f])
- j--;
- if(i<j)
- {
- std::swap(a[i] , a[j]);
- while(a[i] < a[f]) i++;
- while(a[j]>a[f]) j--;
- }
- std::swap(a[f] , a[j]);
- sorting(f , j-1);
- sorting(j+1 , l);
- }
- }
Add Comment
Please, Sign In to add comment