Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- BUBBLE SORT
- static memory allocation
- 1 based indexing
- ** for TURBO C, remove // from commented lines
- */
- #include<stdio.h>
- //#include<conio.h>
- #define swap(x,y) {temp = x; x = y; y = temp;}
- void BUBBLE_SORT(int *arr, int arr_length){
- int i, j, temp;
- for(i = 1; i<= arr_length - 1; i++){
- for(j = arr_length; j >= (i+1); j--){
- if(arr[j] < arr[j-1]){
- swap(arr[j], arr[j-1]);
- }
- }
- }
- }
- int main(){
- int i, len, arr[11];
- //clrscr();
- printf("\nEnter length (max 10): "); scanf("%d", &len);
- printf("\nEnter %d elements one after another:\n", len);
- for(i=1; i<=len; i++) scanf("%d", &arr[i]);
- printf("\nOriginal Array ::\n\t");
- for(i=1; i<=len; i++) printf("%d ", arr[i]);
- BUBBLE_SORT(arr, len);
- printf("\nSorted Array ::\n\t");
- for(i=1; i<=len; i++) printf("%d ", arr[i]);
- printf("\n");
- //getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement