Advertisement
Guest User

Untitled

a guest
Feb 14th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. void sorArray(int *arr, int len){
  5.  
  6. int start=0, end=len-1;
  7.  
  8. while (start < end)
  9. {
  10.  
  11. while (arr[start] == 0 && start < end)
  12. start++;
  13.  
  14.  
  15. while (arr[end] == 1 && start < end)
  16. end--;
  17.  
  18.  
  19. if (start < end)
  20. {
  21. arr[start] = 0;
  22. arr[end] = 1;
  23. start++;
  24. end--;
  25. }
  26. }
  27.  
  28. for(int i=0;i<len;i++)
  29. printf("%d\n",arr[i]);
  30.  
  31.  
  32.  
  33.  
  34. }
  35.  
  36. int main(){
  37.  
  38. int arr[] = {0,0,1,1,0,1,0,1,0,1,0,0,0,1};
  39.  
  40. printf("Data in arry is\n");
  41. for(int i=0;i<14;i++)
  42. printf("%d data\n",arr[i]);
  43.  
  44. sorArray(arr,14);
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement