본문 바로가기
728x90

c#102

[CS : 디자인패턴] 싱글톤(Singleton) 디자인패턴에서 생성패턴의 하나인 싱글톤. 수업에서 계속 다뤄 구조와 의미는 알지만, 스스로 싱글톤이 뭐야?라고 했을 때 쉽게 대답하기 어려웠다. 다른 디자인패턴을 공부하기 전에 개념적으로 확실히 하고 싶어 다시 공부하며 복습하였다. 싱글톤(Singleton) 한 클래스가 한 개의 인스턴스만 갖도록 제한. 프로그램 시작부터 종료까지 동일한 인스턴스로 반환되어 전역 범위에서 접근 가능하게 하는 패턴이다. 중앙에서 관리 혹은 정보 공유가 필요할 때 주로 쓰인다. 장점 하나의 인스턴스를 공유하며 사용하기 때문에 생성 비용이 줄어듦 단점 의존성이 높아짐 - 독립적인 테스트가 어려워짐 의존성 주입 결합을 느슨하게 만들어줌 장점 모듈들을 쉽게 교체 가능한 구조가 되어 테스트가 쉬워짐 의존성 방향이 일관됨 쉽게 추론 .. 2023. 4. 13.
[알고리즘] 재귀함수 재귀함수의 대표적인 예 팩토리얼과 피보나치수열로 재귀함수를 연습하였다. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace reflexive { class Program { static void Main() { int input = 5; int factorial = Factorial(input); Console.WriteLine("{0}! = {1}", input, factorial); int fibpnacci = FibonacciN(input); Console.WriteLine("{0}번째 항 : {1}", input, fibpna.. 2023. 2. 8.
[BOJ C#] 10162 전자레인지 using System; namespace _10162 { class Program { static void Main(string[] args) { int a = 300; int b = 60; int c = 10; int t = int.Parse(Console.ReadLine()); if (t % 10 != 0) Console.WriteLine("-1"); else { int clickA = t / a; t = t % a; int clickB = t / b; t = t % b; int clickC = t / c; Console.WriteLine("{0} {1} {2}", clickA, clickB, clickC); } } } } 2023. 1. 31.
[자료구조] 그래프 BFS(너비우선탐색) 그래프의 탐색 -길이우선탐색(DFS) : 자식까지 탐색 후 다른 형제 노드를 탐색 -너비우선탐색(BFS) : 자식 전에 모든 현재 노드를 탐색_Tree Node의 label 탐색과 같음 방문테이블과 Queue를 사용하여 탐색 C# using System; using System.Collections.Generic; using System.Text; namespace BFSpractice { class Program { static int[,] map = { { 0, 1, 1, 0, 0, 0, 0 }, { 1, 0, 0, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 1, 1 }, { 0, 1, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0.. 2023. 1. 30.
[C# 알고리즘] 무방향 그래프 2차원 배열로 구현하기 1: 서울 2: 대구 3: 대전 4: 부산 가중치 x using System; using System.Linq; namespace Graph { class Node { public string data; public Node(string data) { this.data = data; } } class Graph { private Node[] nodes; int[,] maps; public Graph(int n) { this.nodes = new Node[n]; maps = new int[n+1, n+1]; } public void AddVertex(Node node) { this.nodes.Append(node); } public void AddEdge(int n0, int n1) { maps[n0, n.. 2023. 1. 30.
[ C# ] 인벤토리 구현 App Class using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace cshNHR { class App { //생성자 public App() { Inventory inventory = new Inventory(2); inventory.AddItem(new Weapon("장검")); inventory.AddItem(new Weapon("장검")); inventory.AddItem(new Weapon("단검")); inventory.AddItem(new Weapon("창")); inventory.AddItem(new Armor("가죽옷".. 2023. 1. 26.
728x90