SHARE
TWEET

Untitled

a guest Apr 20th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;              
  3. public class Program
  4. {
  5.     private static void solveTowers(int n, char startPeg, char endPeg, char tempPeg)
  6.         {
  7.             if (n > 0)
  8.             {
  9.                 solveTowers(n - 1, startPeg, tempPeg, endPeg);
  10.                 Console.WriteLine("Move diskll from " + startPeg + ' ' + endPeg);
  11.                 solveTowers(n - 1, tempPeg, endPeg, startPeg);
  12.  
  13.             }
  14.         }    
  15.     public static void Main()
  16.     {
  17.          char startPeg = 'A'; // start tower in output
  18.             char endPeg = 'C'; // end tower in output
  19.             char tempPeg = 'B'; // temporary tower in output
  20.             int totalDisks = 3; // number of disks
  21.  
  22.             solveTowers(totalDisks, startPeg, endPeg, tempPeg);
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top