Java backtracking algorithm demonstration code

From , 4 Years ago, written in Java, viewed 50 times.
URL https://pastebin.vip/view/426bf156
  1. package com.lh.DataConsutror;
  2.  
  3. public class BacktrackTest
  4. {
  5.         static int [] array = new int[3];
  6.         static boolean [] flag = new boolean[3];
  7.        
  8.         public static void backTrack(int length)
  9.         {
  10.                 int len = array.length;
  11.                 if(length == len)
  12.                 {
  13.                         for(int i = 0; i < array.length; i++)
  14.                         {
  15.                                 System.out.print(array[i]);
  16.                         }
  17.                         System.out.println();
  18.                 }
  19.                 for(int j = 0; j < len; j++)
  20.                 {
  21.                         if(flag[j] == false)
  22.                         {
  23.                                 array[j] = j + 1;
  24.                                 flag[j] = true;
  25.                                 backTrack(length + 1);
  26.                                 flag[j] = false;
  27.                         }
  28.                 }
  29.         }
  30.        
  31.         public static void main(String[] args)
  32.         {
  33.                 backTrack(0);
  34.         }
  35. }
  36.  
  37. //java/5758

Reply to "Java backtracking algorithm demonstration code"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website