반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | class StationList{ public String name; public int next; } public class Main { public static StationList[] list = new StationList[10]; public static int head; public static void initStationList() { for(int i = 0; i < list.length; i++) { list[i] = new StationList(); } list[0].name = "부산"; list[0].next = -1; list[1].name = "대전"; list[1].next = 3; list[2].name = "서울"; list[2].next = 4; list[3].name = "동대구"; list[3].next = 0; list[4].name = "천안아산"; list[4].next = 1; head = 2; } public static void printStationList() { int idx = head; while(idx != -1) { System.out.print("[" + list[idx].name + "] -> "); idx = list[idx].next; } System.out.println(); } public static void insertStationList(int insIdx, String insName, int prevIdx) { list[insIdx].name = insName; list[insIdx].next = list[prevIdx].next; list[prevIdx].next = insIdx; } public static void deleteStationList(int delIdx, int prevIdx) { list[prevIdx].next = list[delIdx].next; } public static void main(String[] args) { initStationList(); printStationList(); insertStationList(5, "광명", 2); printStationList(); deleteStationList(5,2); printStationList(); } } | cs |
반응형
'공부 > Algorithm 이론' 카테고리의 다른 글
퀵정렬 예제소스 (0) | 2023.01.25 |
---|---|
LinkedList 예제 java (0) | 2023.01.19 |
정렬 기본 예제 소스 O(N^2) (0) | 2023.01.08 |
이진 탐색 (0) | 2023.01.07 |