hi guys:) i am facing a problem:-/
it is a recursive function and one of its parameters is of type list
when the function reaches its end and goes back the list won't be like the old one:?: but it will be updated with the newer on in the last function
see this code it is a code for a program to make a permutation of 5 numbers 0 1 2 3 4
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace _recursion
{
class Program
{
public void recursion(List<int>history,List<int > available)
{
if (available.Count == 0)
{
for (int i = 0; i < history.Count; i++)
{
Console.Write(history[i].ToString() + "->");
}
Console.WriteLine(" ");
return;
}
for (int i = 0; i < available.Count; i++)
{
history.Add(available[i]);
available.RemoveAt(i);
recursion(history,available );
available.Add(history[history.Count - 1]);
history.RemoveAt(history.Count - 1);
}
return;
}
bool[] b = new bool[5]; int [] place = new int [5];
public List<int> find_available_places(List <int > available)
{
for (int i = 0; i < 5; i++)
{
place[i] = i;
}
for (int i = 0; i < 5; i++)
{
if (b[i] == false)
{
available.Add(place[i]);
}
}
return available;
}
static void Main(string[] args)
{
Program p = new Program();
p.recursion(new List<int>(),p.find_available_places(new List<int>()));
}
}
}