Basic CompSci Help Required (C)

Status
Not open for further replies.

Chairman85

Member
I need to write a function that recursively generates all permutations of the set of integers {1, 2 ... n^2} and store them in an array of size n^2. I'm at a loss as to how to go about it. Any help would be greatly appreciated.

This needs to be in C, by the way.

Edit: My mistake 0 should be 1
 
3?

Wait read the problem wrong.

Ok so you need all the permutations of numbers 0-9 if n is 3 correct?

Then you're suppose to store it in an array of size 9?

How is that possible since there would be 10! different permutations for that set of numbers.......?
 
Its a Comp Sci Project, where each permutation is to be tested for a certain condition. 3 is not as small as it appears, as (3^2)! = 362880.
 
Create a vector of size n^2. Fill it with the numbers.

Then use the stl's next_permutation algorithm!

Its almost like cheating!

EDIT: If you could use C++ that is.
 
Status
Not open for further replies.
Top Bottom