I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
COST (GBP)
this unit 0.19
sub units 0.00
+
0

Check

Checks whether an array represents a permutation.
Controller: CodeCogs

add cart

Interface

C++

Check

 
boolcheckintn
int*p )
This function verifies that each of the integers from 1 to n occurs among the entries of the given array, in other words checking if it is a permutation.

Example:

#include <codecogs/maths/combinatorics/permutations/check.h>
#include <iostream>
int main()
{
  int sigma[5] = {1, 3, 2, 3, 4}, tau[4] = {4, 3, 2, 1};
  std::cout << "Sigma is ";
  std::cout << (Maths::Combinatorics::Permutations::check(5, sigma) ? "" : "not ");
  std::cout << "a valid permutation.";
  std::cout << std::endl;
  std::cout << "Tau is ";
  std::cout << (Maths::Combinatorics::Permutations::check(4, tau) ? "" : "not ");
  std::cout << "a valid permutation.";
  std::cout << std::endl;
  return 0;
}

Output:

Sigma is not a valid permutation.
Tau is a valid permutation.

References:

SUBSET, a C++ library of combinatorial routines, http://www.csit.fsu.edu/~burkardt/cpp_src/subset/subset.html

Parameters

nthe size of the p array
pthe actual array

Returns

true, if p is a valid permutation, false otherwise

Authors

Lucian Bentea (August 2005)
Source Code

Source code is available when you buy a Commercial licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.