Guest User

Untitled

a guest
Jan 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. int main()
  2. {
  3. int a[] = {-1, 0, -2, 3, -4, 5};
  4. int n = sizeof a / sizeof *a;
  5.  
  6. int l = 0, r = n - 1;
  7. for( ;; )
  8. {
  9. /* skip positives on the left */
  10. while( l < r && a[l] >= 0 )
  11. l++;
  12. /* skip negatives on the right */
  13. while( l < r && a[r] < 0 )
  14. r--;
  15.  
  16. if ( l >= r ) break;
  17.  
  18. /* swap the negative on the left with the positive on the right */
  19. int t = a[l];
  20. a[l] = a[r];
  21. a[r] = t;
  22. l++, r--; /* not necessary but saves comparisons */
  23. }
  24.  
  25. for( l = 0; l < n; l++ )
  26. printf("%dn", a[l]);
  27.  
  28. return 0;
  29. }
  30.  
  31. j=0
  32.  
  33. for i=0 to n
  34.  
  35. do if (a[i]<0)
  36.  
  37. then a[i] <-> a[j] //swapping
  38.  
  39. j=j+1
  40.  
  41. -------------------------------------------------------
  42.  
  43. #include<stdio.h>
  44.  
  45. int main()
  46. {
  47. int a[]={-1,-2,-4,0,1,4,-5,-3};
  48. int n=sizeof(a)/sizeof(int);
  49. int i,j;
  50. for(i=0,j=0;i<n;i++)
  51. {
  52. if(a[i]<0)
  53. {
  54. int temp;
  55. temp=a[i];
  56. a[i]=a[j];
  57. a[j]=temp;
  58. j++;
  59. }
  60. }
  61. for(i=0;i<n;i++)
  62. printf("%dt",a[i]);
  63. return 0;
  64. }
Add Comment
Please, Sign In to add comment