Home » Ask & Discuss » Board Exams - CBSE, ICSE, State Boards » Computer Science « Back to Discussion
Computer Science
Comments (6)
13 Mar 2008 16:30:10 IST
Like
0 people liked this
thanks lampard.
can you explain the logic for wriiting these sorting.my teacher told us to mug up .but i didn't want to mug up.
please explain them stepwise
and if possible explain with the help of examplesso that i can understand better.
PLEASE REPLY SOON...............
can you explain the logic for wriiting these sorting.my teacher told us to mug up .but i didn't want to mug up.
please explain them stepwise
and if possible explain with the help of examplesso that i can understand better.
PLEASE REPLY SOON...............
13 Mar 2008 16:38:23 IST
Like
2 people liked this
http://www.cosc.canterbury.ac.nz/mukundan/dsal/SSort.html
http://www.cosc.canterbury.ac.nz/mukundan/dsal/ISort.html
http://www.cosc.canterbury.ac.nz/mukundan/dsal/BSort.html
these animations will tell u the logic. u 've to figure out what each line means.
http://www.cosc.canterbury.ac.nz/mukundan/dsal/ISort.html
http://www.cosc.canterbury.ac.nz/mukundan/dsal/BSort.html
these animations will tell u the logic. u 've to figure out what each line means.
13 Mar 2008 16:46:59 IST
Like
1 people liked this
For insertion sort-
for(i=1;i<n;i++)
{
temp=a[i];//a[n] is an array to be sorted.Now consider a[0] as 95 and a[1] as 45
c=i-1; // When i is 1,c will be 0.
while((temp<a[c])&&(count>=0)) //Since temp is 95 which is > than 45,while loop will be executed.
{
a[c+1]=a[c]; //here,we are making a[c+1],i.e,a[1]=a[0],so a[1] becomes95.
c=c-1; //now c has become -1.
}
a[c+1]=temp; //now,a[c+1],i.e a[0] is given value of temp,i.e. 45...
}
Thus after for loop is executed for i=1,a[0] has become 45 and a[1] has become 95...similarly,for loop will also be executed for i=2,3,...,n....so each element will be thus compared with previous elements...hope u got it..
for(i=1;i<n;i++)
{
temp=a[i];//a[n] is an array to be sorted.Now consider a[0] as 95 and a[1] as 45
c=i-1; // When i is 1,c will be 0.
while((temp<a[c])&&(count>=0)) //Since temp is 95 which is > than 45,while loop will be executed.
{
a[c+1]=a[c]; //here,we are making a[c+1],i.e,a[1]=a[0],so a[1] becomes95.
c=c-1; //now c has become -1.
}
a[c+1]=temp; //now,a[c+1],i.e a[0] is given value of temp,i.e. 45...
}
Thus after for loop is executed for i=1,a[0] has become 45 and a[1] has become 95...similarly,for loop will also be executed for i=2,3,...,n....so each element will be thus compared with previous elements...hope u got it..













Selection sort-One way to perform it is to select the smallest element from the unsorted portion of the array and put the element in the ordered position,which starts from the first position of the array,pushing the unsorted portion one portion to the right.
I dunno about deletion sort.
In for loops,for eg. you want to do an operation for a particular number of times,den we use for loop.
In while loops,you first put a condition such that if the variable or any other character satisfies that condition,den it will go into the while loop.
In do while loops,the variable or character first goes into the loop and then it is checked whether its satisfies the condition or not.
If u didn understand sumthing,plz clarify it.