• Post Reply Bookmark Topic Watch Topic
  • New Topic

purpose of a function  RSS feed

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the first loop switches the i'th member backoward like in insertion sort till it gets a valuse smalle then maxvalue
but it switch always with a[i-2]
so i cant see the purpose


the second loop does a similar thing
but i cant see what is the general purpose
??


 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value of i changes each time through the loop so a[i-2] refers to a different element of the array each time.

The first loop moves some elements of the array forward two elements.
The second loop moves some elements of the array forward one element.

Try printing out the values of the array at the start and after each loop if you're still not sure what is happening.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!