Home Forums C Programming Bubble sorting

Viewing 1 reply thread
  • Author
    Posts
    • #1882
      JAZYY18
      Participant

      Here is visual bubble sorting  program enjoy it
       

      #include
      #include
      #include
      void object(int,int,int);
      void bubble(int);
      void flow(int,int);
      void mixing(int,int);
      int el[10];
      void main()
      {
       int n,i,d=0,m=0;
       clrscr();
       printf("Enter the No of Elements : " );
       scanf("%d",&n);
       for(i=0;i  {
        printf("Enter the %d Element : ",i+1);
        scanf("%d",&el);
       }
       initgraph(&d,&m,"");
       settextstyle(3,0,1);
       outtextxy(250,50,"GIVEN NUMBERS ");
      // outtextxy(250,260," AFTER SORTING ");
      // line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
       for(i=0;i  {
        object(100+i*50,150,el);
        getch();
       }
       bubble(n);
      /* for(i=0;i  {
        object(100+i*50,350,el);
        getch();
       }*/
       getch();
      }
      void bubble(int n)
      {
       int i,j,temp;
       for(i=0;i   for(j=i;j    if(el>el[j+1])
         {
          flow(i,j+1);
          temp=el;
          el=el[j+1];
          el[j+1]=temp;
         }
      }
      void object(int x,int y,int no)
      {
       char s[8];
       sprintf(s,"%d",no);
       circle(x,y,15);
       settextstyle(2,0,6);
       outtextxy(x-3,y-10,s);
      }
      void flow(int f,int s)
      {
       int i;
       for(i=0;i<50;i++)
       {
        setcolor(WHITE);
        object(100+f*50,150+i*4,el[f]);
        delay(15);
        setcolor(0);
        object(100+f*50,150+i*4,el[f]);
       }
       setcolor(WHITE);
       object(100+f*50,150+i*4,el[f]);
       for(i=0;i<50;i++)
       {
        setcolor(WHITE);
        object(100+s*50,150+i*4,el);
        delay(10);
        setcolor(0);
        object(100+s*50,150+i*4,el);
       }
       setcolor(WHITE);
       object(100+s*50,150+i*4,el);
       mixing(f,s);
       for(i=50;i>0;i--)
       {
        setcolor(WHITE);
        object(100+f*50,150+i*4,el);
        delay(10);
        setcolor(0);
        object(100+f*50,150+i*4,el);
       }
       setcolor(WHITE);
       object(100+f*50,150+i*4,el);
       for(i=50;i>0;i--)
       {
        setcolor(WHITE);
        object(100+s*50,150+i*4,el[f]);
        delay(15);
        setcolor(0);
        object(100+s*50,150+i*4,el[f]);
       }
       setcolor(WHITE);
       object(100+s*50,150+i*4,el[f]);
      }
      void mixing(int f,int s)
      {
       int i;
       for(i=0;i<(s-f)*50;i++)
       {
        setcolor(WHITE);
        object(100+f*50+i,350,el[f]);
        object(100+s*50-i,350,el);
        delay(20);
        setcolor(0);
        object(100+f*50+i,350,el[f]);
        object(100+s*50-i,350,el);
        }
        setcolor(WHITE);
        object(100+f*50+i,350,el[f]);
        object(100+s*50-i,350,el);
      }

    • #3137
      msaqib
      Participant

      Nice effort spsinghs.

Viewing 1 reply thread
  • The forum ‘C Programming’ is closed to new topics and replies.