• Post Reply Bookmark Topic Watch Topic
  • New Topic

I need help with HashMap.  RSS feed

 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to randomly generate preference list for men.
(I am working on match making code so each man and woman should have preference list for their opposite sex)
Here is my code.

My Output:

This is not what I wanted. look at last row it is not shuffled too.
I want output like this

each man preference list should have different preference list. (what I mean is each men should have different preference list)
can you guys help me to solve this problem?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Erdene Yadam wrote:
can you guys help me to solve this problem?


You only have one women list. So, for each man, you shuffle the one women list, and then you tell the man to use the one list. At the end, you have all your men pointing to the same list.

What you need to do is... for each man, you shuffle the one (original) women list, make a copy of the list, and then you tell the man to use the copy of the list. At the end, you have all your men with their own lists, that are shuffled differently -- and of course, your one original women list.

Henry
 
Erdene Yadam
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


how to shuffle every men's preference list.
I have used collections shuffle but it does not shuffle every list. it shuffles it once. I dont understand why
M1, M2, M3, M4, M5 they all have same list.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am not sure of your followup question. I have already answered why you are getting the output you are seeing, along with how to fix it.

Henry
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!