wood burning stoves 2.0*
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 Java 8 in Action this week in the Java 8 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: 13884
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
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!)

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: difference between [--nItems] and [nItems-1]??
 
Similar Threads
Adding Values To Array & Moving Other Values Down
Regarding PriorityQueue
java.lang.NullPointerException at runtime
Priority queue
Priority Queue and iterator