시뮬레이션 알고리즘 문제로 Queue를 이용했다.
핵심이 중요도와 맨 처음 위치의 인덱스이기 때문에, 2가지 값을 포함하는 Custom Class를 만들었다.
class Document{
int initialIndex;
int importance;
}
테스트 케이스를 여러 개 입력받기 때문에, Queue<Document>를 변수로 가지고 있는 Custom Class를 만들었다.
class Case{
int indexToFind;
Queue<Document> docuList;
}
현재 Pop하는 값이 Queue 내부 값 중 가장 큰 값인지를 확인하기 위해서 Queue.Max() 함수를 사용했다.
Custom Class를 자료형으로 사용하기 때문에 Max() 함수가 두 값을 비교할 때 사용할 CompareTo() 함수를 추가하였다.
CompareTo() 함수를 커스텀하기 위해서는 IComparable 클래스를 상속받아야 한다.
public int CompareTo(Document? other)
{
if(this.importance > other!.importance)
return 1;
else if (this.importance == other.importance)
return 0;
else
return -1;
}
나머지는 문제에 요구하는 대로 구현!