public void insert(String genre, String title) { GenreNode genreToInsert = findGenreNode(genre); TitleNode titleToInsert; if (genreToInsert == null) { // 장르 먼저 만든다. genreToInsert = new GenreNode(genre); GenreNode temp; GenreNode position = findGenrePosition(genre); temp = position.getNextGenre(); position.setNextGenre(genreToInsert); genreToInsert.setNextGenre(temp); } if (genreToInsert.isExistTitle(title) == false) { // 장르가 있는 경우이다. 이때는 타이틀만 넣어주면 된다. titleToInsert = new TitleNode(title); TitleNode temp; TitleNode position2 = genreToInsert.findTitlePosition(title); temp = position2.getNextTitle(); position2.setNextTitle(titleToInsert); titleToInsert.setNextTitle(temp); } }
public void delete(String genre, String title) { GenreNode genreToDelete = findGenreNode(genre); if (genreToDelete == null) return; TitleNode titleToDelete = genreToDelete.findTitleNode(title); if (titleToDelete == null) return; TitleNode titlePrev = genreToDelete.findTitlePosition(title); titlePrev.setNextTitle(titleToDelete.getNextTitle()); if (genreToDelete.getTitleHead().getNextTitle() == null) { GenreNode genrePrev = findGenrePosition(genre); genrePrev.setNextGenre(genreToDelete.getNextGenre()); } }