OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   RE: [xml-dev] Beauty is in the eye of the beholder (was: Are we ready...

[ Lists Home | Date Index | Thread Index ]

<snip/>
> Hmmm. Is the following Dijkstra-ascribed permutation algorithm
> (implementation in Java purely my fault) beauteous or just way too clever?:
> 
> 
> public class Permuter extends Object
> {
>    int m_level;
>    int[] m_value;
>    int m_permCt = 0;
> 
>    public Permuter(int size)
>    {
>       m_level = -1;
>       m_value = new int[size];
>    }
> 
>    public void permute()
>    {
>       visit(0);
>       System.out.println("\nTotal permutations = " + m_permCt);
>    }
> 
>    public void visit(int k)
>    {
>       m_level++;
>       m_value[k] = m_level;
> 
>       if (m_level == m_value.length)
>       {
>          addPermutation();
>       }
>       else
>       {
>          for (int i = 0; i < m_value.length; i++)
>          {
>             if (m_value[i] == 0)
>                visit(i);
>          }
>       }
> 
>       m_level--;
>       m_value[k] = 0;
>    }
> 
>    void addPermutation()
>    {
>       for (int i = 0; i < m_value.length; i++)
>       {
>          System.out.print(m_value[i] + " ");
>       }
> 
>       System.out.println();
> 
>       m_permCt++;
>    }
> 
> }
> 
> I have a hard enough time tracing through this in a debugger without getting
> lost. Works pretty fast, though, I will admit.
> >

at least i can read it....

one of the many reasons i don't use debuggers is that they are difficult
to drive in a recursive algorithm (we still teach those i hope). easier
to sit and think about what's really happening, run a couple of tests,
and move on.

;)

rick





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS