Dress element selection algorithm Selection source code

zhaozj2021-02-16  84

// Copyright (C) 2004 BenBear //// This file is an algorithm of selection This library is free // software;. You can redistribute it and / or modify it under the // terms of the GNU General Public License as published By The // Free Software Foundation; Either Version 2, or (at Your Option) // Any Later Version.

// This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY;. Without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the // GNU General Public License for more details.

. // You should have received a copy of the GNU General Public License along // with this library; see the file COPYING If not, write to the Free // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111- 1307, // USA.

#include #include #include using namespace std;

Template BOOLNEXT_SELECTION (Biiter First, Biiter Last {if (first == last) Return False; Biiter i = Last; if (--i == first) Return False; Biiter J = i; if (* - -i == 0) {while ((i! = first) && (* i == 0)) --I; if (* i == 0) {ified_swap (first, j); return false;} Biiter II = I; * ( ii) = * j 1; * j = 0; - * i;} else {- * i; * j;} return true;}

Template BoolPrev_Selection (Biiter First, Biiter Last) {IF (First == Last) Return False; Biiter I = Last; --i; if (First == i) Return False; if (* i == 0 ) {While (* - i == 0); if (i == first) {* - last = * i; * i = 0; returnaf false;} biiter j = i; --j; * J; - * i; it_swap (i, --last);} else {biiter j = i; --j; * j; - * i;} return true;} // for test: int main () {Const INT n = 4; int A [n] = {0, 0, 0, 3}; do {for (int i = 0; i

System ("pause");

转载请注明原文地址:https://www.9cbs.com/read-12131.html

New Post(0)