자료구조 직접 구현 해보기2 - ArrayList (Feat. Java)

이미지
지난번에 이어서, 이번에는 ArrayList를 허접하게 구현해보았다. 제너릭을 사용했고, Iterable 인터페이스를 구현하여, iterator를 오버라이딩하여 foreach문을 사용할 수 있도록 했다. 제너릭이기 때문에 static class로 Developer 클래스를 만들어서 테스트를 해보았다. 이상 허접한 블로깅..

자료구조 직접 구현 해보기1 - Stack (Feat. Java)

이미지
문득 자료구조를 한 번 씩 직접 구현해 보아야지? 라는 생각이 들어서 시작했다. 코드를  https://carbon.now.sh 에서 이미지로 변환해 주는게 있어서 사용했다. 배열로 스택을 구현해보았다. 처음 사이즈는 10이고 엘리먼트가 10개 보다 많아질때 마다 배열의 길이를 원본 + 10 증가시켜주게 짰다. 아래 코드는 간단하게 int 타입만 MyStack에 지원된다. 이 코드를 제너릭으로 바꿔 보아야 겠다. 아래 코드는 제너릭을 사용 가능하도록 해보았다. 제너릭 배열을 사용해서 짜보았다. 제너릭을 사용 할 때 배열 대신 리스트를 사용해라고들 하는데 정확한 이유는 모르겠다. 더 찾아보고 공부를 해야겠다고 느꼈다. casting 할 때 문제점이 있다고 하는데 얼추 무슨 느낌인지는 알겠는데, 정확히는 모르겠다. 제너릭이기 때문에 예시로 Person 클래스를 만들어서 사용해보았다.

HackerRank Java Climbing the Leaderboard

이미지
문제풀기 :  https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem Alice is playing an arcade game and wants to climb to the top of the leaderboard and wants to track her ranking. The game uses  Dense Ranking , so its leaderboard works like this: The player with the highest score is ranked number   on the leaderboard. Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number. For example, the four players on the leaderboard have high scores of  ,  ,  , and  . Those players will have ranks  ,  ,  , and  , respectively. If Alice's scores are  ,   and  , her rankings after each game are  ,   and  . Function Description Complete the  climbingLeaderboard  function in the editor below. It should return an integer array where each element  represents Alice's rank after the...