C#递归跳过选项

时间:2014-04-26 10:16:08

标签: c# recursion

我正在使用递归构建一个shift组织器。我的问题是递归并不是每个可能的解决方案。我正在添加递归代码(至少是重要的部分。有人可以解释一下我的错误吗?

static bool Proccess(Point pos, User[] users, Shift shifts)
{
  if (shifts.CheckFull())
  {
    //if the solotion is better than the saved one, replace it
    return false;
  }
  Sort(users) // Sorts the users by number of shifts given to them so far (Ascending)
  if (shifts.GetShiftEmptySpace(pos) != 0)
    for (int i = 0; i < users.Length; i++)
    {
        if (users[i].GetPrefs(pos) == Prefs.Natural)
           AddShift(users,pos,shifts,i);
    }
  if (shifts.GetShiftEmptySpace(pos) != 0)
    for (int i = 0; i < users.Length; i++)
    {
        if (users[i].GetPrefs(pos) == Prefs.Comp_Unprefered)
           AddShift(users,pos,shifts,i);
    }
}

static void AddShift(User[] users, point pos, Shift shifts, int num)
{
  Shift shiftsTemp = new Shift();
  User userTemp = new User("");

  userTemp.CopyFromUser(users[num]);
  shiftsTemp.CopyFromShifts(shifts);

  shifts.AddShift(pos, users[num].Name, users[num].GetPref(pos));
  users[num].AddShift(pos);

  Proccess(shifts.GetNext(), users, shifts);

  users[num].CopyFromUser(userTemp);
  shifts.CopyFromShifts(shiftsTemp);
}

0 个答案:

没有答案