• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Sorting Collections Doubt

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

If, there are two or more elements are same in a list(dvdList). I get different output at different time of execution. Is that how sorting algorithm work in collections?




Thanks
Saritha
[ September 27, 2008: Message edited by: saritha babu ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you show us the comparator code? Could you show us sample data? Could you show us sample output? Etc...

Obviously, a sorting algorithm that sorts differently, depending on time of day, is *not* how it is supposed to work.

Henry
 
aslika bahini
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Could you show us the comparator code? Could you show us sample data? Could you show us sample output? Etc...



Hi Henry,

Here is the Comparator code...



first output is:

[Raiders of the Lost Ark action Ford, Harrison
, Patriot Games action Ford, Harrison
, Caddy Shack comedy Murray, Bill
, Lost in Translation comedy Murray, Bill
, Donnie Darko sci-fi Gyllenhall,Jake
, 2001 sci-fi ??
, Star Wars sci-fi Ford, Harrison
]
second output is:

[Patriot Games action Ford, Harrison
,Raiders of the Lost Ark action Ford, Harrison
, Caddy Shack comedy Murray, Bill
, Lost in Translation comedy Murray, Bill
, Donnie Darko sci-fi Gyllenhall,Jake
, 2001 sci-fi ??
, Star Wars sci-fi Ford, Harrison
]

Thank you
Saritha
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Saritha!
I am not sure if i am right, but i am guessing that you are only sorting the collection just by the genre.
The "toString()" method for "DVDInfo" object is this:

then the output you have is sorted by genre.
Look at it again, genre is sorted.

........action..............
........action..............
........comedy..........
........comedy.........
........sci-fi........
........sci-fi........
........sci-fi.......



(in both outputs)

The collection is not sorted by the title so the DVDInfo objects that has the same genre but different titles can switch their order but only within each other.
You will not have comedy or Sci-fi come before action, no matter how many times you run the code.

It would be easy to answer your question if you write all of the code for this program. Like how you are sorting (compareTo or Compare method) the main method etc.

[ September 27, 2008: Message edited by: Shiraz Choudhary ]
[ September 27, 2008: Message edited by: Shiraz Choudhary ]
 
aslika bahini
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shiraz Choudhary,

It would be easy to answer your question if you write all of the code for this program. Like how you are sorting (compareTo or Compare method) the main method etc



Here is the code...
I think I am little confused. I get the same result when I execute this time. The result in book(pg 555) and mine is different. Thanks for the help.



Thanks
Saritha
 
reply
    Bookmark Topic Watch Topic
  • New Topic