public TitleNode findTitlePosition(String title) { TitleNode curr = this.getTitleHead(); while (curr.getNextTitle() != null) { if (curr.getNextTitle().getTitleData().compareToIgnoreCase(title) >= 0) break; curr = curr.getNextTitle(); } return curr; }
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 TitleNode findTitleNode(String title) { TitleNode curr = this.getTitleHead(); while (curr != null) { if (curr.getTitleData().equals(title)) { return curr; } curr = curr.getNextTitle(); } return null; }
public boolean isExistTitle(String title) { TitleNode curr = this.getTitleHead(); while (curr != null) { if (curr.getTitleData().equals(title)) { return true; } curr = curr.getNextTitle(); } return false; }
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()); } }
public void printListAll(List printList) { GenreNode curr = printList.head; if (curr.getNextGenre() == null) { System.out.println("EMPTY"); } else { for (curr = printList.head.getNextGenre(); curr != null; curr = curr.getNextGenre()) { for (TitleNode curr2nd = curr.getTitleHead().getNextTitle(); curr2nd != null; curr2nd = curr2nd.getNextTitle()) { System.out.println("(" + curr.getGenreData() + ", " + curr2nd.getTitleData() + ")"); } } } }
public void search(String keyword) { GenreNode curr = this.head; String cache = ""; for (curr = this.head.getNextGenre(); curr != null; curr = curr.getNextGenre()) { for (TitleNode curr2nd = curr.getTitleHead().getNextTitle(); curr2nd != null; curr2nd = curr2nd.getNextTitle()) { if (curr2nd.getTitleData().contains(keyword)) { System.out.println("(" + curr.getGenreData() + ", " + curr2nd.getTitleData() + ")"); cache = "*"; } } } if (cache.equals("")) { System.out.println("EMPTY"); } }