Permutation

This content presents you with some possible coding method for permutation. I don’t create them by myself. Instead of that, I’ve just bring some interesting algorithms to present here.

  1. Alexander Bogomolyn’s unordered permutation algorithm
    #include <stdio.h>
    void visit(int *Order, int N,int k){
      static int level=-1;
      level+=1;Order[k]=level;
      if(level==N) print(Order,N);
      // function print for printing all elements in Order
      else
        for(int i=0;i<N;i++)
          if(Order[i]==0) visit(Order,N,i);
      level=level-1;Order[k]=0;
    }
    
    main(){
      const int N=4;
      int Order[N];
      for(int i=0;i<N;i++) Order[i]=0;
      visit(Order,N,0);
    }
    
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s