I have a homework assignment for my algorithms class, we need to take up to 10 user inputted locations and then plot out the route from a static point, displaying every possible route to take.

What I'm wondering is is there a way to randomly display a string array and avoiding duplicates?

I know how to randomize an int array, but that deals with numbers only.

Thanks.

Recommended Answers

All 8 Replies

>>What I'm wondering is is there a way to randomly display a string array and avoiding duplicates?

If I have an array of x unique strings I could write code to display all x strings randomly, but display each string only one time, yes. If that's what you are asking.

I can also display all elements in an array in all possible unique combinations if that's what you mean.

>>What I'm wondering is is there a way to randomly display a string array and avoiding duplicates?

If I have an array of x unique strings I could write code to display all x strings randomly, but display each string only one time, yes. If that's what you are asking.

I can also display all elements in an array in all possible unique combinations if that's what you mean.

Displaying them in all possible unique combinations is what I'm looking for. Can you give an example of how to accomplish it?

Displaying them in all possible unique combinations is what I'm looking for. Can you give an example of how to accomplish it?

You're asking for a solution to your homework? I'll give you a hint: Depth First Search.

You're asking for a solution to your homework? I'll give you a hint: Depth First Search.

Only good for a tree. I think you mean Permutations.

Only good for a tree. I think you mean Permutations.

Or good for a graph. Suppose that the cities are a fully connected graph ( which it sounds like they are ), then doing a depth first traversal of the graph from each node will render every possible permutation.

Duskreader - thanks for the tip, the depth first traversal is a method covered in my text so that'll work for what I need.

Now on a side note, I really wasn't asking for anyone to *DO* the work, I just needed a simple example of doing a random output of string arrays. I wasn't really sure if the same function used for INT arrays also covered other types as well.

"One of the most frightening things about your true nerd, for may people, is not that he's socially inept - because everybody's been there - but rather his complete lack of embarrassment about it."
--Neal Stephenson .

Just to be a grammar police here, but you forgot the "n" in many "for maNy people."

Just to be a grammar police here, but you forgot the "n" in many "for maNy people."

Thanks, i'll fix that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.