permute.h

来自「数据结构c++语言描述 Borland C++实现」· C头文件 代码 · 共 21 行

H
21 行
字号

// randomly permute an array

#ifndef Permute_
#define Permute_

#include <stdlib.h>
#include "swap.h"

template <class T>
void Permute(T a[], int n)
{// Permute a[0:n-1].

   for (int i = n - 1; i > 0; i--)
      // swap a[i] with a randomly selected element
      // from a[0:i]
      Swap(a[i], a[random(i+1)]);
}

#endif

⌨️ 快捷键说明

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