Advertisement
dllbridge

Untitled

Apr 8th, 2024
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1.  
  2.  
  3.  
  4. #include <stdio.h>
  5.  
  6.  
  7.  
  8. //////////////////////////////////////////////////////
  9. void swap(int &n1, int &n2)
  10. {
  11.    
  12.      int n3 = n1;
  13.      
  14.      n1 = n2;
  15.      n2 = n3;
  16. }
  17.  
  18.  
  19. //////////////////////////////////////////////////////
  20. void sort(int *p, int n)                            //
  21. {
  22.    
  23.      int nF;
  24.      
  25.      
  26. L_01:   nF = 0;
  27.    
  28.      for(int i = 0; i < n-1; i++)
  29.      {
  30.            
  31.            
  32.            
  33.         if( p[i] > p[i+1] ) { nF = 1; swap( p[i],  p[i+1] ); } 
  34.      }
  35.    
  36.    
  37.      if(nF) goto L_01;    
  38. }
  39.  
  40. ////////////////////////////////////////////////////////
  41. void print(int *p, int n)
  42. {
  43.      for(int i = 0; i < n; i++)
  44.      {
  45.            
  46.         printf("%d, ", p[i]);      
  47.      } 
  48.    
  49. }
  50.  
  51.  
  52. ///////////////////////////////////////////////////////
  53. int main()
  54. {
  55.     int mas[99] = {5, 11, 2, 6, 34, 1, 7};
  56.  
  57.  
  58.     sort(mas, 7);
  59.    
  60.     print(mas, 7);
  61. //  system("pause");
  62.     return 0;
  63. }
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement