Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int d[1000], i, n=0, j=0, temp, right, left, temp2;
- printf("Podaj ile chcesz liczb: ");
- scanf("%d", &n);
- for(i=0;i<n;i++)
- {
- printf("Podaj liczby: ");
- scanf("%d", &d[i]);
- }
- printf("Nieposortowany: [");
- for(i=0;i<n;i++)
- {
- printf("%d", d[i]);
- if(i!=n-1)
- {
- printf(", ");
- }
- }
- printf("]\n");
- left=0;
- right=n-1;
- do{
- do{
- i=(left+right)/2;
- temp=d[i];
- d[i]=d[right];
- j=left;
- i=left;
- while(i<right)
- {
- if(d[i]<temp)
- {
- temp2=d[i];
- d[i]=d[j];
- d[j]=temp2;
- j++;
- }
- i++;
- }
- d[right]=d[j];
- d[j]=temp;
- right=j-1;
- }
- while(left<j-1);
- left=j+1;
- }
- while(j+1<right);
- printf("Posortowany: [");
- for(i=0;i<n;i++)
- {
- printf("%d", d[i]);
- if(i!=n-1)
- {
- printf(", ");
- }
- }
- printf("]\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement