[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Beauty is in the eye of the beholder (was: Are we ready...


RE:  Beauty is in the eye of the beholder (was: Are we ready...
<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


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.