Advertisement
Shailrshah

Bubble Sort

Nov 5th, 2014
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.36 KB | None | 0 0
  1. #! /bin/awk
  2. BEGIN{
  3.     printf("Enter the number of terms: ");
  4.     getline n;
  5.     printf("Enter the elements.\n");   
  6.     for(i=0; i<n; i++) getline a[i];
  7.  
  8.     for(i=0; i<n; i++)
  9.         for(j=i+1; j<n; j++)
  10.             if(a[i]>a[j]){
  11.                 temp=a[i];
  12.                 a[i]=a[j];
  13.                 a[j]=temp;
  14.             }
  15.            
  16.     for(i=0; i<n; i++) printf("%d", a[i]);
  17. }
  18.  
  19. #Save as bSort.awk, run by typing awk -f bSort.awk
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement