linked list (5) 썸네일형 리스트형 자료구조/Python3) 연결 리스트로 큐 구현하기 Queue는 선입선출 (First In First Out) 형식의 자료구조이다. 브라우저가 Javascript를 동작시킬 때 api콜, setTimeout 등 비동기로 처리할 수 있는 함수들은 콜 스택에 쌓지 않고 web api에서 비동기로 처리한 후 처리 결과와 함께 콜백 함수를 테스크 큐에 넣는다. 이 때 테스크 큐가 큐 구조로 이루어져 선입선출 방식으로 작동한다. python에서는 collections라는 라이브러리에 deque 모듈을 임포트해서 사용하면 간단하지만 원리를 이해하기 위해 연결리스트로 구현해보았다. class Node 연결리스트의 노드는 각 노드의 값과 다음 노드를 가리키는 포인터로 이루어져있다. class Node: def __init__(self, data) -> None: sel.. 자료구조/Python3) 연결리스트로 스택 구현 후입 선출 (Last in First Out) 자료구조인 스택은 Python에서 이미 list[]라는 자료형으로 구현되어 있다. 그래서 내장된 append, pop 함수를 이용해서 push,pop 메소드를 간단하게 구현할 수 있다. 그래서 이번에는 리스트 자료형을 사용하지 않고 각 노드가 next 노드에 대한 포인터를 가지고 있는 연결리스트로 스택을 구현해보았다. class Node class Node: def __init__(self, data): self.data = data self.next = None 연결 리스트의 각 노드들은 값(=data)을 가지고 다음 노드에 대한 포인터 (=next)를 갖는다. class Stack 스택은 기본적으로 top 포인터를 가지고 있다. LIFO 구조로 데이터에 .. 자료구조/C) 연결리스트를 이용한 실습 문제 풀이 문제 소스코드 #include #include typedef struct node { int coef; int exp; struct node* next; } Node; Node* newNode(int c, int e) { Node* p = (Node*)malloc(sizeof(Node)); p->coef = c; p->exp = e; p->next = NULL; return p; } Node* appendTerm(Node *k, int c, int e) { //k는 마지막항 Node* t = newNode(c, e); Node* khead = newNode(NULL, NULL); khead->next = k; while ((khead->next) != NULL) { khead = khead->next; .. 연결리스트 자료구조를 이용해서 구현한 다항식 계산기 #include #include typedef struct node { int coef; int exp; struct node* next; } Node; Node* newNode(int c, int e) { Node* p = (Node*)malloc(sizeof(Node)); p->coef = c; p->exp = e; p->next = NULL; return p; } Node* appendTerm(Node* k, int c, int e) { Node* t = newNode(c, e); Node* khead = newNode(0, 0); khead->next = k; while ((khead->next) != NULL) { khead = khead->next; } khead->next = t; retur.. 연결리스트 삽입, 삭제, 출력 Linked List insert delete print 구현하기 연결리스트 Linked List 성균관대학교 소프트웨어학과 조대호 교수님의 2020년도 2학기 알고리즘 수업을 들으며 수행한 과제입니다. problem Write functions which perform according to the following descriptions. The input to each function is a linked list of integers. a) insert - Inserts an integer x to the front of a linked list. e.g.) insert(lst, x) where lst is a pointer to a linked list and x is an integer. b) delete - Deletes 2 nd last integer x.. 이전 1 다음