CS/자료구조
-
Swift에서 힙, 우선순위 큐 사용하기 (100% 순수 구현을 곁들인)CS/자료구조 2024. 7. 30. 16:51
안녕하세요, 자료구조로 글쓰는 건 정말 오랜만입니다.Swift에서 우선순위 큐 코드를 코테에서나, 코딩 인터뷰때 사용한다면 어떻게 할까? 부터 시작해 이글을 쓰게 되었습니다.현재 제 주력언어는 Swift로, Heap과 관련된 서드파티 라이브러리 같은 게 있을거 같은데 코테에서나 인터뷰에선 해당 라이브러리를 쓰자니 곤란합니다. 물론 제한사항도 있을거구요. 다른 언어를 사용해도 되지만, 너무 단순한 대체법인 거 같습니다. 물론 사용해도 문제가 없고 다른 언어를 알고 있다면 상관 없겠지만요. 그래서 뭘 말하려고 하냐면 옛날에 큐 관련 자료를 정리 해놓고 구현해 놓았던 Heap과 우선순위 큐, 그리고 이를 사용할 수 있는 설명과 구현 코드를 제시하려 합니다. [Swift 우선순위 큐 구현코드]struct Glo..
-
[whiteship스터디 4주차 과제]LinkedList를 이용해 Queue 구현CS/자료구조 2021. 6. 19. 11:50
큐의 FIFO 특징을 간단하게 구현했습니다. Main 클래스 package Week4_Queue_ListNode; public class Test { public static void main(String[] args) { Queue queue = new Queue(); for (int i = 0; i < 3; i++) { queue.push(i); } System.out.println("Queue Size : " + queue.size); queue.showItems(); System.out.println(queue.pop().data); System.out.println(queue.pop().data); System.out.println(queue.pop().data); System.out.print..
-
[whiteship스터디 4주차 과제]ListNode클래스를 이용해 Stack구현CS/자료구조 2021. 5. 16. 10:39
과제 4. 앞서 만든 ListNode를 사용해서 Stack을 구현하세요. ListNode head를 가지고 있는 ListNodeStack 클래스를 구현하세요. void push(int data)를 구현하세요. int pop()을 구현하세요. package Week4_Stack_ListNode; public class ListNode { public int data; public ListNode next; ListNode(){ this.data = 0; this.next=null; } } package Week4_Stack_ListNode; public class Stack { public ListNode head; public int size = 0; public void push(int data) { ..
-
[whiteship스터디 4주차 과제]배열을 이용한 스택 구현CS/자료구조 2021. 5. 15. 09:40
Stack 클래스 package Week3_Stack; public class Stack { private int[] list; private int pointer; private int size; Stack(int size) { this.pointer = 0; this.size = size; this.list = new int[size]; } void push(int data) { if (pointer >= size) { System.out.println("OverFlow"); return; } list[pointer] = data; pointer++; //스택의 상태를 출력 for (int i = 0; i ");..
-
[whiteship스터디]single linked list 구현CS/자료구조 2021. 4. 11. 13:52
과제 2. LinkedList를 구현하세요. LinkedList에 대해 공부하세요. 정수를 저장하는 ListNode 클래스를 구현하세요. ListNode add(ListNode head, ListNode nodeToAdd, int position)를 구현하세요. ListNode remove(ListNode head, int positionToRemove)를 구현하세요. boolean contains(ListNode head, ListNode nodeTocheck)를 구현하세요. 2021.01.26 - [스터디/[whiteship]JAVA] - [4주차]제어문 [노드 클래스] public class Node { public T data; public Node next; public Node(T data) ..