⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perm_book.cpp

📁 这是本人精心搜集的关于常用图论算法的一套源码
💻 CPP
字号:
#include <iostream.h>
void permute(int new_entry, int degree, int *permutation);
void process_permutation(int *permutation);
const int max_degree=5;
void main( )
/* Pre: The user specifies the degree of permutations to construct.
   Post: All permutations of a user-supplied degree are printed to the terminal. */
{ int degree, permutation[max_degree+1];
  cout<<"Number of elements to permute? ";
  cin>>degree;
  if(degree<1 || degree>max_degree)
     cout<<"Number must be between 1 and " << max_degree<<endl;
  else {  permutation[0] = 0;
          permute(1, degree, permutation);
       }
}

void permute(int new_entry, int degree, int *permutation)
/* Pre: permutation contains a linked permutation with entries in positions1 through new_entry-1 .
  Post: All permutations with degree entries, built from the given permutation, 
        have been constructed and processed.
  Uses: Functionspermute (recursively) andprocess_permutation . */
{  int current = 0;
   do{ permutation[new_entry] = permutation[current];
       permutation[current] = new_entry;
       if(new_entry==degree) process_permutation(permutation);
        else  permute(new_entry+1, degree, permutation);
       permutation[current] = permutation[new_entry];
       current = permutation[current];
     } while (current != 0);
}

void process_permutation(int *permutation)
/* Pre: permutation is in linked form.
  Post: The permutation has been printed to the terminal. */
{  int current = 0;
   while(permutation[current] != 0) 
   {  cout<<permutation[current] << " ";
      current = permutation[current];
   }
  cout << endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -