aspose file tools*
The moose likes Beginning Java and the fly likes difference between [--nItems] and [nItems-1]?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "difference between [--nItems] and [nItems-1]??" Watch "difference between [--nItems] and [nItems-1]??" New topic
Author

difference between [--nItems] and [nItems-1]??

Nadine Ernest
Greenhorn

Joined: Dec 10, 2008
Posts: 27
In the priority queue,
i dont understand these two methods....

they are the opposite of what should be done,, i think they give the maximum but in the data structures book it says the following

to remove the minimum:


and the other method is to peek on the minimum in the PRIORITY QUEUE:


this way, its gonna peek on the maximum --------> this is what i think

but the right thing is that it peeks on the minimum without changing anything this is from the book and my lectures so its correct but i just dont get it soo please help???


What Doesn't Kill You, Makes You Stronger!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14420
    
  23

The difference between the two methods you posted is this:

In the first version, you are decrementing the variable nItems. So the value of the variable nItems is changed.
In the second version, you are not changing the value of the variable nItems.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Nadine Ernest
Greenhorn

Joined: Dec 10, 2008
Posts: 27
aha...thank youuuu soo much!!

i totally misunderstood the whole thing,,,i read it upside down! (silly me!)

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: difference between [--nItems] and [nItems-1]??