백준 [28278] - 스택2 (C++), Stack Class 구현
·
개발/알고리즘
문제 문제 설명 - stack의 기본적인 함수인 push, pop, size, empty, top을 구현하는 문제이다. 이번에는 Stack 라이브러리를 사용하지 않고, 직접 class로 stack을 구현해 문제를 풀어보았다. Stack.h 코드 #include #pragma once class Stack { private: int* arr; int capacity; int n; int stack_top; public: Stack(int capacity); bool empty(); int size(); int top(); void push(int data); int pop(); }; Stack::Stack(int capacity) { this->capacity = capacity; arr = new int..
[Spring] @RestController와 @Controller의 차이점
·
개발/JAVA
@Controller 이해하기 내가 처음 스프링의 MVC패턴에 대해 배울 때에는 controller에서 @Controller 어노테이션을 사용해서 View를 반환하는 방식을 배웠었다. [Controller로 View 반환 예제코드] @Controller public class MemberController { private final MemberService memberService; @Autowired public MemberController(MemberService memberService) { this.memberService = memberService; } @GetMapping("/members/new") public String createForm(){ return "members/creat..
백준[1406] -에디터 (C++)
·
개발/알고리즘
오늘은 연결리스트에 대해서 공부했다. 연결리스트란? 연결리스트(Linked List)는 각 노드(Node)가 데이터와 포인터를 가지고 한 줄로 연결되어 있는 방식으로 데이터를 저장하는 자료구조이다. - 각 노드는 다음 노드를 가리키는 포인터를 포함한다. 각 노드의 포인터는 다음 노드의 데이터의 주소를 값으로 가진다. 이런 특징들을 가진 연결리스트를 구현하기 위해 구조체로 연결리스트를 구현해보았다. 연결리스트 구현 struct Node { char data; struct Node* next; }; void PrintList(Node* head) { Node* cursor = new Node(); if (head == NULL) { cout next; while (cursor != NULL) { cout d..
백준 [3273] - 두 수의 합 (C++)
·
개발/알고리즘
처음 이 문제를 봤을 때는 라이브러리의 find함수를 이용해서 풀면 될 것이라고 생각했다. 그래서 벡터에 입력된 수를 채워넣고 ex) x = 13, v[0] = 5이면 x - v[0]인 8을 벡터에서 찾고, 있으면 두 원소를 벡터에서 지우는 방식으로 시간을 줄이려고 했다. #include #include #include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vector v; int n, a, x, cnt = 0; cin >> n; for (int i = 0; i > a; v.push_back(a); } cin >> x; for (int i = 0; i < n-1;..
개발민
'분류 전체보기' 카테고리의 글 목록 (2 Page)