Home › Forums › C Programming › Bubble sorting
- This topic has 1 reply, 2 voices, and was last updated 19 years, 9 months ago by msaqib.
Viewing 1 reply thread
- AuthorPosts
- February 19, 2005 at 12:40 am #1882JAZYY18Participant
Here is visual bubble sorting program enjoy it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121#include<stdio.h><br />#include<conio.h><br />#include<graphics.h><br />void object(int,int,int);<br />void bubble(int);<br />void flow(int,int);<br />void mixing(int,int);<br />int el[10];<br />void main()<br />{<br />int n,i,d=0,m=0;<br />clrscr();<br />printf("Enter the No of Elements : " );<br />scanf("%d",&n);<br />for(i=0;i<n;i++)<br />{<br />printf("Enter the %d Element : ",i+1);<br />scanf("%d",&el);<br />}<br />initgraph(&d,&m,"");<br />settextstyle(3,0,1);<br />outtextxy(250,50,"GIVEN NUMBERS ");<br />// outtextxy(250,260," AFTER SORTING ");<br />// line(0,getmaxy()/2,getmaxx(),getmaxy()/2);<br />for(i=0;i<n;i++)<br />{<br />object(100+i*50,150,el);<br />getch();<br />}<br />bubble(n);<br />/* for(i=0;i<n;i++)<br />{<br />object(100+i*50,350,el);<br />getch();<br />}*/<br />getch();<br />}<br />void bubble(int n)<br />{<br />int i,j,temp;<br />for(i=0;i<n;i++)<br />for(j=i;j<n-1;j++)<br />if(el>el[j+1])<br />{<br />flow(i,j+1);<br />temp=el;<br />el=el[j+1];<br />el[j+1]=temp;<br />}<br />}<br />void object(int x,int y,int no)<br />{<br />char s[8];<br />sprintf(s,"%d",no);<br />circle(x,y,15);<br />settextstyle(2,0,6);<br />outtextxy(x-3,y-10,s);<br />}<br />void flow(int f,int s)<br />{<br />int i;<br />for(i=0;i<50;i++)<br />{<br />setcolor(WHITE);<br />object(100+f*50,150+i*4,el[f]);<br />delay(15);<br />setcolor(0);<br />object(100+f*50,150+i*4,el[f]);<br />}<br />setcolor(WHITE);<br />object(100+f*50,150+i*4,el[f]);<br />for(i=0;i<50;i++)<br />{<br />setcolor(WHITE);<br />object(100+s*50,150+i*4,el);<br />delay(10);<br />setcolor(0);<br />object(100+s*50,150+i*4,el);<br />}<br />setcolor(WHITE);<br />object(100+s*50,150+i*4,el);<br />mixing(f,s);<br />for(i=50;i>0;i--)<br />{<br />setcolor(WHITE);<br />object(100+f*50,150+i*4,el);<br />delay(10);<br />setcolor(0);<br />object(100+f*50,150+i*4,el);<br />}<br />setcolor(WHITE);<br />object(100+f*50,150+i*4,el);<br />for(i=50;i>0;i--)<br />{<br />setcolor(WHITE);<br />object(100+s*50,150+i*4,el[f]);<br />delay(15);<br />setcolor(0);<br />object(100+s*50,150+i*4,el[f]);<br />}<br />setcolor(WHITE);<br />object(100+s*50,150+i*4,el[f]);<br />}<br />void mixing(int f,int s)<br />{<br />int i;<br />for(i=0;i<(s-f)*50;i++)<br />{<br />setcolor(WHITE);<br />object(100+f*50+i,350,el[f]);<br />object(100+s*50-i,350,el);<br />delay(20);<br />setcolor(0);<br />object(100+f*50+i,350,el[f]);<br />object(100+s*50-i,350,el);<br />}<br />setcolor(WHITE);<br />object(100+f*50+i,350,el[f]);<br />object(100+s*50-i,350,el);<br />}<br /> - February 19, 2005 at 9:25 am #3137msaqibParticipant
Nice effort spsinghs.
- AuthorPosts
Viewing 1 reply thread
- The forum ‘C Programming’ is closed to new topics and replies.