분류 전체보기 (73) 썸네일형 리스트형 [알고리즘] 위상정렬 위상 정렬, topological sort순서가 정해져있는 작업을 차례로 수행해야 할 때 사용DAG(Directed Acyclic Graph)에만 적용 가능 / 사이클이 발생하지 않는 방향 그래프시간 복잡도: O(V+E)/정점 개수 + 간선 개수 예시> 대학의 선수과목(prerequisite)만약 특정 수강과목에 선수과목이 있다면 그 선수 과목부터 수강해야 하므로, 특정 과목들을 수강해야 할 때 위상 정렬을 통해 올바른 수강 순서를 찾아낼 수 있다. 이와 같이 선후 관계가 정의된 그래프 구조 상에서 선후 관계에 따라 정렬하기 위해 위상 정렬을 이용할 수 있다. Queue로 구현- 깊이가 0이 정점 큐에 삽입- 큐에서 정점 꺼내서 연결된 모든 간선 제거- 간선 제거하면서 방문한 정점은 깊이 1씩 감소-.. [softeer/c++] 좌석 관리/string 비교 string 비교함수 compare#include string s;if(s.compare("string") == 0) cout compare함수는 두 문자열이 같으면 0, 다르면 -1 반환 틀렸을 때- sqrt 함수 사용한 safety 변수를 double로 받아야 하는데 int로 했었음- 메모리 해제를 안 했음 #include #include #include #include #include #include using namespace std;int N, M;int **seat; //N+1*M+1 배열double cal_safety(int x, int y){ //(x,y) 좌석의 안전도 구하기 double min = 40.0; for(int i=1; i max_safety(){ //안전.. [Rust] 시작하기 (m1) 1. 터미널에 명령어 입력curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 2. 환경변수 업데이트source $HOME/.cargo/env 3. 터미널 껐다 켜야됨 -> 버전 확인rustc --version 공식 문서에 따르면 아래와 같은 에디터 지원Rust support is available in many editors:VS CODEVIM/NEOVIMRUSTROVERHELIXEMACSSUBLIME TEXTVISUAL STUDIOECLIPSE [TypeScript] Interfaces type Team = "red" | "blue" | "yellow"type Health = 1 | 5 | 10interface Player { nickname: string, team: Team health: Health}Interfaces는 한 가지 용도만을 가짐object 모양을 특정하기 위함 TypeScript에게 object 모양을 알려주기 위한 방법은 1. Type - 좀 더 유연함2. Interfaces - 객체 지향 프로그래밍의 개념을 활용해서 디자인 interface User { name:string}// interface는 새 타입, 필드를 정의할 떄 기존 이름 사용 가능interface User { nickname:string}interface Player e.. [TypeScript] 객체지향 - Classes * JavaScript는 제공하지 않는 기능들private, publicclass Player { constructor( private firstName:string, private lastName:string, public nickname:string ) {}}const seojin = new Seojin("seojin", "moon", "문");seojin.firstName # errorseojin.nickname abstract 클래스, abstract 메소드(클래스 안의 함수)abstract class User { constructor( constructor( private firstName:string, # priva.. [TypeScript] 다형성(Polymorphism) type SuperPrint = { (arr: number[]) : void (arr: booleanp[) : void (arr: string[]): void}const superPrint: SuperPrint = (arr) => { arr.forEach(i => console.log(i))}superPrint([1, 2, 3, 4])superPrint([true, false, false])superPrint(["a", "b", "c"])> void, boolean, unknown 이런 건 concrete type type SuperPrint = { # 타입스크립트에게 이 callsignature가 generic을 받는다는 걸 알려주는 방법 (arr: TypePla.. [TypeScript] 기본 문법 - 함수 함수를 선언하는 여러가지 방법#1 function add(a:number, b:number): number { return a+b}#2const add = (a:number, b:number) => a+b#3; call signatures, 함수의 파라미터와 리턴 타입을 명시하는 것type Add = (a:number, b:number) => number;const add:Add = (a,b) => a + b Overloading- 직접 쓸 일은 많지 않겠지만 외부 패키지나 라이브러리에서는 오버로딩을 많이 사용하기 때문에 알아둘 필요가 있음- 함수가 서로 다른 여러 개의 call signatures를 가지고 있을 때 발생type Add = { (a:number, b:number) : numbe.. [TypeScript] 기본 문법 - Type Implicit TypesJavaScript처럼 변수만 생성하고 넘어가도 타입 추론 가능let a = "hello"a = "bye"a = 1 # error Explicit Types데이터와 변수의 타입을 명시적으로 정의let : = let a = "hello"let b : boolean = "x" # error Object에 Type 선언const player : { # 타입 선언 name: string, # 반드시 필요 age?:number # ?를 붙이면 optional} = { # 실제 내용 name:"seojin"}if(player.age > player를 여러 개 만들고 싶다면Alias 타입type Player = { name:string, age.. 이전 1 2 3 4 5 ··· 10 다음