| Author |
Message |
![[Post New]](/templates/default/images/icon_minipost_new.gif) 13 Mar 2008 15:25:31 IST
|
|
|
HELLO EVERYONE.................... PLEASE EXPLAIN THE LOGIC OF INSERTION,SELECTION AND DELETION SORT.ALSO EXPLAIN THE LOGIC OF FOLLOWING LOOPS: 1.FOR 2.WHILE 3.DO WHILE HOPING FOR GOOD REPLIES!!!!!!
|
|
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 13 Mar 2008 16:25:28 IST
|
|
|
Insertion sort-See,insertion sort is carried out round after round.In the K-th round,the Kth element is considered.By comparison with the previous (K-1) elements of the array,its proper position is determined.The element is then inserted into that position after shifting the succeeding elements one place each to the right.
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.
|
MaNuTd RoXxXx..MaNuTd 2 WiN PrEmIeR LeAgUe ThIs SeAsOn ToO AlOnG WiTh ChAmPiOnS LeAgUe.....HaiL RoNaLdO ...HaiL LaMpArD... |
this reply: 5 points
(with 1 
in 1 votes ) [?]
|
|
You have to be logged on to rate
|
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 13 Mar 2008 16:30:10 IST
|
|
|
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...............
|
this reply: 0 points
(with 0 
in 0 votes ) [?]
|
|
You have to be logged on to rate
|
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 13 Mar 2008 16:38:23 IST
|
|
|
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.
|
this reply: 5 points
(with 1 
in 1 votes ) [?]
|
|
You have to be logged on to rate
|
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 13 Mar 2008 16:46:59 IST
|
|
|
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..
|
MaNuTd RoXxXx..MaNuTd 2 WiN PrEmIeR LeAgUe ThIs SeAsOn ToO AlOnG WiTh ChAmPiOnS LeAgUe.....HaiL RoNaLdO ...HaiL LaMpArD... |
this reply: 5 points
(with 1 
in 1 votes ) [?]
|
|
You have to be logged on to rate
|
|
|
![[Post New]](/templates/default/images/icon_minipost_new.gif) 14 Mar 2008 07:34:29 IST
|
|
|
THANKS
|
this reply: 0 points
(with 0 
in 0 votes ) [?]
|
|
You have to be logged on to rate
|
|
|
|
|