in the right direction? For example I have a link list of strings:
C A T
the number of permutations is 6 (3! = 3x2x1) so the different arrangements of letters would go like this
C A T
A C T
A T C
T A C
T C A
C T A
If I have the algorithm I can do the rest myself. This is what I have tried so far
void permute::permutation(int n)
{
node *rightNeighbor;
node *nextRightNeighbor;
node *previousNeighbor;
//cout<<" numberOfNodes "<<numberOfNodes<<" n = "<<n<<endl<<endl;
if( n == numberOfNodes )
{
return;
}
else
{
if(n == 1)
{
anchor = firstNode; /* first letter = first node (c) is the anchor */
}
rightNeighbor = anchor->Link();
nextRightNeighbor = rightNeighbor->Link();
if( nextRightNeighbor != NULL)
{
nextRightNeighbor = rightNeighbor->Link();
}
else
{
nextRightNeighbor = NULL;
}
previousNeighbor = rightNeighbor;
anchor->set_link( nextRightNeighbor );
rightNeighbor->set_link( anchor );
firstNode = rightNeighbor;
rightNeighbor = anchor->Link();
if(rightNeighbor->Link() == NULL)
{
nextRightNeighbor = NULL;
}
permutation(n + 1);
}
printList();
}/* end permutation */

New Topic/Question
Reply



MultiQuote




|