Site icon T4Tutorials.com

write a c program to sort a 1d array using pointer by applying bubble sort technique

write a c program to sort a 1d array using pointer by applying the bubble sort technique.

/* 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]);


 }

 

Exit mobile version