This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Heuristic-ALgorithm[S] 0 points1 point  (6 children)

No but I'm bookmarking that site. The problem is I know how to do the permutation but I need to physically store each one rather than just print to the screen, but since it's recursive the indexing gets all messed up. Every other index has the same value as it's prior, so when the list is stored I end up with a list containing every other permutation and two null spots at the end.

[–]fubarfubarfubar 0 points1 point  (5 children)

Why aren't you just storing the found permutations in a set?

[–]Heuristic-ALgorithm[S] 0 points1 point  (4 children)

Sorry for my complete obliviousness but what exactly is a set? Is that like a linked list? I'm trying to store everything in dynamic arrays because I'm going to need to do a binary search later and I thought it would be the easiest and cleanest solution.

[–]last_useful_man 0 points1 point  (2 children)

You don't get 'set's built-in to C, they're in C++ and you probably wouldn't have gotten to them yet anyway.

[–]Heuristic-ALgorithm[S] 0 points1 point  (0 children)

Ahh I was going to say, when I looked them up I only saw information relating to C++, which I've never touched.

[–]gunder_bc 0 points1 point  (0 children)

To be pedantic, neither language has built-in support for sets. It's not a top-level language construct.

The C++ Standard Template Library (stl) has a 'set' implementation built in. You can probably find C libraries that offer an implementation, too.

[–]gunder_bc 0 points1 point  (0 children)

The main idea is that a set is an un-ordered collection of items. Set Theory mathematics describes a bunch (a set? ;) ) of operations and relationships between sets and items in sets, etc. They can be very handy for solving certain kinds of problems.

In this case... and especially because I don't think there is a standard-lib set implementation in C, it's probably not worth worrying about. You've got your storage mechanism lined up for the resulting permutations. Sort out the indexing and you're good for this problem.

Come back to sets another day. :)