Skip to content

Conversation

deipanema
Copy link
Member

구현 방법

  1. 테스트케이스 예제를 가져옵니다.
  2. 📂 21. 스택 + 큐 폴더에 있는 스택 구현 방식을 차용하였습니다.
  3. for 루프를 N만큼 돌려 테스트 케이스를 확인합니다.
    4-1. 테스트 케이스 명령어와 동일하다면 함수를 호출합니다. 이 때, case "push": 제외하고 result 변수에 값을 더해줍니다.
  4. result 문자 데이터를 빈 칸 기준 잘라서 배열로 만들어요. 그리고 한 줄 띄워서 문자 데이터로 만듭니다. 이것은 Output입니다.

아이디어

  • 배열 요소에 '\r'을 .replace(/\r/g, "") 실행합니다.
  • result 변수에 테스트 케이스 return 결과를 차곡차곡 더해줍니다. 문자 데이터를 쌍 따옴표를 사용했는데 이때, 한 칸씩 띄워줍니다. 왜냐하면 마지막 result를 splite() 함수로 쪼갤 때 음수의 마이너스(-)를 살려주기 위해서 입니다.
  • 조건식으로 명확한 문자 데이터를 사용하기 때문에 if문 보다 switch문이 더 적합합니다.

@deipanema deipanema added 🌝성공 clear queue labels Mar 17, 2023
@deipanema deipanema self-assigned this Mar 17, 2023
@deipanema deipanema linked an issue Mar 17, 2023 that may be closed by this pull request
Copy link
Member

@ViGilanteAF ViGilanteAF left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

switch() 문 을 이용한것이 아주 적합한것 같습니다. 👍

}

empty() {
return !this.size ? 1 : 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!this.size ? 1: 0; 이렇게 쓰는건 처음 봅니다 ㅎㅎㅎ 코드가 간결하게 되니 좋은것 같습니다.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.size === 0 을 짧게 써봤습니다~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BOJ] 18258. 큐 2
2 participants