Mini
[알고리즘] 자바 전역 배열 선언 방법 본문
public class Main {
// 1차원 배열 선언
static int[] arr = new int[100]; // 정수형 배열
static boolean[] visited = new boolean[100]; // 불리언 배열
static char[] chars = new char[100]; // 문자 배열
// 2차원 배열 선언
static int[][] board = new int[100][100]; // 정수형 2차원 배열
static char[][] map = new char[100][100]; // 문자형 2차원 배열
// ArrayList 선언
static ArrayList<Integer>[] graph = new ArrayList[100]; // 인접 리스트
static ArrayList<Integer> list = new ArrayList<>(); // 동적 배열
// Queue, Stack 등 자료구조
static Queue<Integer> q = new LinkedList<>();
static Stack<Integer> stack = new Stack<>();
public static void main(String[] args) {
// 인접 리스트 초기화 (까먹기 쉬움!)
for(int i = 0; i < 100; i++) {
graph[i] = new ArrayList<>();
}
}
}
'Algorithm' 카테고리의 다른 글
C++ split구현, 사용법 (0) | 2023.06.24 |
---|---|
2차원 리스트 사용법 (0) | 2022.08.23 |
순열 VS 조합 vs 부분집합 코드 (0) | 2022.08.19 |
팁 (0) | 2022.08.09 |