Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array problem

 
peterx peter
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
This is an insertion sort program, the program is OK
But my question is about out put of (j):
--------------------------------------------------
A[j + 1] = a;
System.out.print(j+" ");
--------------------------------------------------
The out put is -1,0,0,-1,1,-1,1)
Which (j) dose take these values and how dose it work???

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best way to understand would be to run the program in a debugger and step through it one statement at a time, paying attention to the values of all the relevant variables. Of course, first you'd have to be sure to understand the algorithm being used.
 
Ramesh Shanmugam
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is values of J that you decrease using J-- in the forloop..

each time it decreases J's value and that leads to 1, 0, -1 etc....
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic