write a c program to sort a 1d array using pointer by applying the bubble sort technique.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | /* BUBBLE_SORT PROGRAM IN C USING POINTERS - BUBBLEBUBBLE_SORT.C */ #include<stdio.h> int *t4tutorials[100],i,j,piece; int main() { void BUBBLE_SORT(),show(); //function declarations int i; printf("\n Enter the number of elements in the first array\n"); scanf("%d",&piece); //reding elements from user printf("\n Enter %d numbers\n",piece); for(i=0;i<piece;++i) scanf("%d",&t4tutorials[i]); BUBBLE_SORT(); //calling BUBBLE_SORT function to perform bubble BUBBLE_SORT show(); //calling show function to show elements } void BUBBLE_SORT() //BUBBLE_SORT function to BUBBLE_SORT elements { int swap=1,*temp; for(i=0;i<piece && swap==1;++i) { swap=0; for(j=0;j<piece-(i+1);++j) if (t4tutorials[j]>t4tutorials[j+1]) { temp=t4tutorials[j]; t4tutorials[j]=t4tutorials[j+1]; t4tutorials[j+1]=temp; swap=1; } } } void show() //show function { printf("\n BUBBLE_SORTed elements are:\n"); for(i=0;i<piece;++i) printf("%d\n",t4tutorials[i]); } |