여기에서 Space는 (xposition, yposition, zposition, length, depth, height)를 요소로 갖는 클래스이며 유형 공백 목록이 있습니다.두 개의 공간 객체를 단일 공간으로 병합
조건에있는 일부 조건을 따르는 지 여부는 목록에서 확인해야합니다.
만족하면 두 공간을 단일 공간으로 병합합니다. 그 후, 내가 사용한 공간을 모두 제거합니다. 실제로는 두 공간을 단일 공간으로 병합하는 것을 의미합니다.
새 목록이 만들어집니다. 다시 나는 그것을 새로운 목록으로 간주하고 조건을 만족시키지 않을 때까지 동일한 절차를 수행한다.
내 문제는 무한 루프가 발생한다는 것입니다. 나는 이것을 해결하고 싶다.
public class MergeSpace
{
public List<Space> Mergespace(List<Space> Listofspaces)
{
foreach (Space space1 in Listofspaces)
{
foreach (Space space2 in Listofspaces)
{
//int count = 0;
if ((space1.sheight == space2.sheight)
&& (space1.sdepth == space2.sdepth)
&& (space2.xposition == space1.xposition + space1.slength)
&& (space2.yposition == space1.yposition)
&& (space2.zposition == space1.zposition)
&& (space1.semptyspace == true)
&& (space2.semptyspace == true))
{
Space space = new Space();
space.xposition = space1.xposition;
space.yposition = space1.yposition;
space.zposition = space1.zposition;
space1.slength = space1.slength + space2.slength;
space.sheight = space1.sheight;
space.sdepth = space1.sdepth;
space.semptyspace = true;
Listofspaces.Add(space);
Listofspaces.Remove(space1);
Listofspaces.Remove(space2);
Mergespace(Listofspaces);
}
Listofspaces.Remove (space1)을 피할 생각이 무엇인지 잘 모릅니다
– Sumeshk답장을 보내 주셔서 감사합니다. upls 내가 어떻게 더 잘할 수 있는지 제안 할 수 있습니다. – user3493758