sorting - Counting sort in java for tuples -
I am creating a square in which the magnification of the strings is in the whole, so if I have 3 apples, then I From apple mapping will happen.
I have to write a class that changes the name of objects with decreasing numbers.
So if I
(apple, 3) (orange, 2) (banana, 5)
I (banana, 5), (apples, 3 ), (Orange 2) / P>
I was thinking that there is already a class that will make my life easier or how I will implement it.
Thank you.
Div class = "post-text" itemprop = "text">
You can put your objects (apple, 3) (orange, 2) (bananas, 5) in a list and then Call the collections.sort (your list). Then you want to make sure that the object you have declared has implemented the comparative interface.
More information is available at
. Let's say you have declared
the public class applies the calculations and comparable & lt; Fruit & Count & gt; {The name of the private last string; Private final integer count; Public fruit and count (string name, ant count) {this.name = name; This.count = count; } Name of public string () {name of return; } Public Entitount Count () {Return Count; } To compare public int (fruit and calculation o) {return.count.compareTo (o.count); }}
Then you should be able to call the following sort:
Fruits and Coins [ Apple ", 3), new fruit and count (" orange ", 2), new fruit and count (" banana ", 5)}; & Lt; FruitAndCount & gt; Fruit = erases.salist (fruit); Collections.sort (fruit);
Then you should have a sorted list of fruits.
Comments
Post a Comment