분류 | 게시판 |
베스트 |
|
유머 |
|
이야기 |
|
이슈 |
|
생활 |
|
취미 |
|
학술 |
|
방송연예 |
|
방송프로그램 |
|
디지털 |
|
스포츠 |
|
야구팀 |
|
게임1 |
|
게임2 |
|
기타 |
|
운영 |
|
임시게시판 |
|
옵션 |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #ifndef __DNode_H__ #define __DNode_H__ #include <iostream> #include <string> using namespace std; typedef string Elem; class DNode { private: Elem elem; DNode* prev; DNode* next; friend class DLinkedList; }; #endif | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include "DNode.h" class DLinkedList { public: DLinkedList(); ~DLinkedList(); bool empty() const; const Elem& front() const; const Elem& back() const; void addFront(const Elem& e); void addBack(const Elem& e); void removeFront(); void removeBack(); private: DNode* header; DNode* trailer; protected: void add(DNode* v, const Elem& e); void remove(DNode* v); }; | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include "DLinkedList.h" DLinkedList::DLinkedList() { header = new DNode; trailer = new DNode; header->next = trailer; trailer->prev = header; } DLinkedList::~DLinkedList() { while (!empty()) removeFront(); delete header; delete trailer; } bool DLinkedList::empty() const { return header->next == trailer; } const Elem& DLinkedList::front() const { return header->next->elem; } const Elem& DLinkedList::back() const { return trailer->prev->elem; } void DLinkedList::add(DNode* v, const Elem& e) { DNode* u = new DNode; u->elem = e; u->next = v; u->prev = v->prev; v->prev->next = v->prev = u; } void DLinkedList::addFront(const Elem& e) { add(header->next, e); } void DLinkedList::addBack(const Elem& e) { add(trailer, e); } void DLinkedList::remove(DNode* v) { DNode* u = v->prev; DNode* w = v->next; u->next = w; w->prev = u; delete v; } void DLinkedList::removeFront() { remove(header->next); } void DLinkedList::removeBack() { remove(trailer->prev); } | cs |
죄송합니다. 댓글 작성은 회원만 가능합니다.
번호 | 제 목 | 이름 | 날짜 | 조회 | 추천 | |||||
---|---|---|---|---|---|---|---|---|---|---|
31 | [본삭금] 리눅스 커널 코드 질문이요 ㅠㅠ [1] | 안녕하세 | 19/12/26 17:21 | 49 | 0 | |||||
30 | 웹개발 개인프로젝트 질문입니다 [8] | 안녕하세 | 19/07/04 00:38 | 154 | 0 | |||||
29 | [본삭금] c++ 이진탐색트리 구현 질문입니다.. ㅠㅠ [3] | 안녕하세 | 19/06/05 00:39 | 115 | 0 | |||||
▶ | [본삭금] Doubly Linked List 구현 질문입니다 ㅠㅠ [2] | 안녕하세 | 19/05/11 21:35 | 87 | 0 | |||||
27 | [본삭금] vector stl capacity 질문입니다ㅠㅠ [3] | 안녕하세 | 19/04/28 20:56 | 68 | 0 | |||||
26 | [본삭금] C++ 배열 확장 질문이요 [5] | 안녕하세 | 19/03/22 19:12 | 95 | 0 | |||||
25 | [본삭금] C언어 포인터, 주소 질문입니다. [3] | 안녕하세 | 19/03/14 23:48 | 162 | 0 | |||||
24 | [본삭금] C언어 포인터 질문입니다. [2] | 안녕하세 | 19/03/14 23:44 | 150 | 0 | |||||
23 | [본삭금]삽입정렬 구현인데 오류를 잘 모르겠어요 ㅠㅠ [6] | 안녕하세 | 18/09/18 22:00 | 46 | 0 | |||||
22 | [본삭금] c++ c2664 에러가 나는데 해결방법을 도저히 모르겠습니다 [5] | 안녕하세 | 18/04/17 23:59 | 47 | 0 | |||||
21 | [본삭금] c++ c2664해결방법좀 알려주세요 ㅠㅠ [3] | 안녕하세 | 18/04/15 22:32 | 45 | 0 | |||||
20 | c++ 에러 좀 도와주세요~!!! [2] | 안녕하세 | 15/11/04 22:19 | 25 | 0 | |||||
19 | c++초보자 질문이요 [3] | 안녕하세 | 15/10/24 08:59 | 28 | 0 | |||||
18 | c++ 과제좀 도와주세요~!!! 본삭금 [11] | 안녕하세 | 15/10/23 17:19 | 53 | 0 | |||||
17 | c++ 과제좀 도와주세요~!!! 본삭금 [1] | 안녕하세 | 15/10/12 02:37 | 62 | 0 | |||||
16 | 본삭금 과제질문이요~!~! [1] | 안녕하세 | 15/10/03 17:07 | 32 | 0 | |||||
15 | c++ 과제좀 도와주세요~!!! [2] | 안녕하세 | 15/09/20 19:07 | 37 | 0/4 | |||||
14 | c++ 과제좀 도와주세요~!!! [9] | 안녕하세 | 15/09/18 22:30 | 54 | 0 | |||||
13 | 아래글에 이어서 c++ 과제 도와주세요~!~!~ [5] | 안녕하세 | 15/09/12 17:57 | 41 | 0 | |||||
12 | c++과제좀 도와주세요~!~!~! [4] | 안녕하세 | 15/09/12 17:11 | 61 | 0 | |||||
11 | 본삭금 c언어 질문이요 ㅠㅠ [6] | 안녕하세 | 15/06/08 23:30 | 45 | 0 | |||||
10 | 본삭금 c언어 개초보입니다 ㅠㅠ질문이요 [3] | 안녕하세 | 15/06/07 23:33 | 32 | 0 | |||||
9 | 본삭금 c언어 질문이요 ㅠㅠ [3] | 안녕하세 | 15/06/07 22:53 | 32 | 0 | |||||
8 | 개초보 도와주세요 c언어 ㅠㅠ [2] | 안녕하세 | 15/06/07 18:16 | 45 | 0 | |||||
7 | 포인터 어려워요ㅠㅠ [2] | 안녕하세 | 15/06/07 16:39 | 56 | 0 | |||||
6 | c언어 개초보좀 도와주세요 [2] | 안녕하세 | 15/06/07 16:29 | 35 | 0 | |||||
5 | c언어 질문이요~~ [11] | 안녕하세 | 15/06/06 16:13 | 55 | 0 | |||||
4 | C언어 고수님들아 도와주세요 [2] | 안녕하세 | 15/06/06 14:27 | 59 | 0 | |||||
3 | c언어 개초보좀 도와주세요 [6] | 안녕하세 | 15/06/03 22:35 | 53 | 0 | |||||
2 | 고수님들 c언어 개초보좀 도와주세요 [3] | 안녕하세 | 15/06/03 21:23 | 39 | 0 | |||||
|
||||||||||
[1] [2] | ||||||||||