์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ ?
์ฌ๊ธฐ์ ์ฐ๊ฒฐ ๋ฆฌ์คํธ์ ๋ํ ๊ฐ๋ ์ ์๊ฒ ๋์๊ณ
์ฌ๊ธฐ์ ๋จ์ ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ฅผ ๊ตฌํํด๋ณด์๋ค.
๋, ์์ ํฌ์คํ ์์ ์ฐ๊ฒฐ์ ๋ํ ๋ฐฉ๋ฒ์ ๋งํ๋๋ฐ '์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ' ๋ ์๋ฐฉํฅ(์ด์ค)์ผ๋ก ๊ตฌ์ฑ๋ ์๋ฃ๊ตฌ์กฐ์ด๋ค.
์ฆ, ์ฑ๊ธ ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ ์ฝ์ค ์ฌํ์ด๋ผ๋ฉด ์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ ์์ ์ฌํ์ด๋ค.
์ด์ ๋ํด์ ๋ด๊ฐ ์๊ฐํ ์์์ด๊ธฐ ๋๋ฌธ์ ํ ๋ฒ ์๊ฐํด๋ณด๊ณ ๋น์ทํ ์์๋ฅผ ์ฐพ์์ ๋ณธ์ธ๋ง์ ๊ฐ๋ ์ผ๋ก ์ดํดํ๊ธธ..
์ด๋ฒ STL ๋ฐ๋ผ์ก๊ธฐ ํฌ์คํธ๋ standard library์ธ list๋ฅผ ๋ง๋ค์ด๋ณด๊ฒ ๋ค.
๋จผ์ , list์ ์ด๋ค ๊ธฐ๋ฅ์ด ์๋์ง ํ ๋ฒ ์์๋ณด์.
์ฐ๋ฆฌ๋ STL list์ ์ด๋ค ๊ธฐ๋ฅ์ด ๊ตฌํ๋์ด์๋์ง ํ์ ํ ๋ค์ ์ด๋ฅผ ์ ๋ฆฌํ ๊ฒ์ด๋ค.
๊นํ๋ธ ์ด์์ ๊ตฌํํ ๋ด์ฉ์ ์์ฑํ๊ณ ์ด๋ฅผ ๋ฐํ์ผ๋ก ๋ ํ์งํ ๋ฆฌ์ ์ ์ฅํ ๊ฒ์ด๋ค.
list์ ๋ชจ๋ ๊ธฐ๋ฅ์ ๊ตฌํํ์ง๋ ์๊ณ '์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ'์ ํต์ฌ ๊ธฐ๋ฅ๊ณผ ์ถ๊ฐํ๊ณ ์ถ์ ์์ ์ ๋ํด ์ํํ ๊ฒ์ด๋ค.
์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง ๋ ธ๋ ๋ง๋ค๊ธฐ DoubleLinkedList.h
template <typename T>
class Node {
public:
Node(T data);
T getData() const;
Node* getNext() const;
Node* getPrev() const;
void setNext(Node* node);
void setPrev(Node* node);
private:
T data;
Node* next;
Node* prev;
};
์ฐ๋ฆฌ๊ฐ ๊ฐ์ง ๋ด์ฉ์ ์ฝ๋์ ์์ฑ๋ ๊ทธ๋๋ก์ด๋ค.
๊ฐ ๋ ธ๋๋ ๋ฐ์ดํฐ์ ์ฐ๊ฒฐ๋ ๋ฐ์ดํฐ๋ฅผ ์ฐ๊ฒฐํ ์ ์ ๋ง๋ค์ด์ผ ํ๋ค.
data - ๊ฐ, next - ๋ค์ ๋ ธ๋, prev - ์ด์ ๋ ธ๋
ํด๋น portotype์ ๋ํ ์์ฑ๋ฒ์ ์๋ตํ๊ฒ ์ต๋๋ค.
ํ ๋ฒ, ์ง์ ๊ตฌํํด๋ณด๊ณ ๋ชจ๋ฅด๊ฒ ์ผ๋ฉด ์ ๊นํ๋ธ์์ ์ ๋ต์ ๋ณด๋ ๊ฒ์ ์ถ์ฒํฉ๋๋ค.
โป ์๋ฉด ์ข์ ๊ฐ๋
1. const keyword
get ๋ฉ์๋์ ๋ํด ์์ธํ ๋ณด์. ๋งจ ๋์ const๊ฐ ๋ฌ๋ ค์๋ค.
๋ณ์๋ฅผ ์ ์ธํ๊ธฐ ์ ์ const ๋ณ์๋ช = ๊ฐ; ์ ์ทจํ๋ฉด ํด๋น ๋ณ์๋ ์์ ํ ์ ์๋ '์์'๊ฐ ๋๋ค.
์ฆ, const๋ ์ ๋ณด์ ๋ฌด๊ฒฐ์ฑ(๋ณํ์ง ์๋ ์ฑ์ง)์ ์ง์ผ์ฃผ๋ ํค์๋์ ๋๋ค.
ํด๋น ๋ฉ์๋๋ ์ฐ๋ฆฌ๊ฐ ์ฌ์ฉํ๋ ๋ฉค๋ฒ ๋ณ์์ธ data์ next, prev์ ๋ํด ๋ฌด๊ฒฐ์ฑ์ ๋ณด์ฅํด์ค๋๋ค.
๋ด๋ถ์์ ์์ ๋์ด ์ด์ํ ๊ฐ์ด ์ ๋ฌ๋๋ ๊ฒ์ ๋ง์์ฃผ์ฃ .
2. private access modifier
์ฐ๋ฆฌ๋ ๋ฉค๋ฒ ๋ณ์์ ๋ํด ์ธ๋ถ์์ ์ ๊ทผํ ์ ์๋๋ก ์บก์ํ(encapsulate)๋ฅผ ํ์ต๋๋ค.
์ ๋ณด์๋์ ํตํด ๋ฐ์ดํฐ์ ๋ฌด๊ฒฐ์ฑ, ์ ๋ขฐ์ฑ์ ๋ณด์ฅํฉ๋๋ค.
๋ ธ๋๋ฅผ ๋ง๋ค์์ผ๋ฉด ํด๋น ๋ ธ๋๋ก ์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ฅผ ์์ฑํ๊ธฐ DoublyLinkedList.h
#pragma once
#include "DoublyLinkedListNode.h"
// Prototype
template <typename T>
class DoublyLinkedList {
public:
DoublyLinkedList();
// ๋ฐ๋ณต์
class iterator {
public:
iterator(Node<T>* node, bool& isReverse);
T operator*() const;
iterator& operator++(int);
iterator& operator--(int);
bool operator!=(const iterator& other) const;
private:
Node<T>* it;
bool isReverse;
Node<T>* getNode();
friend class DoublyLinkedList<T>;
};
// Function
iterator begin();
iterator end();
iterator rbegin();
iterator rend();
iterator erase(iterator it);
void push_front(const T& value);
void push_back(const T& value);
void pop_front();
void pop_back();
void insert(iterator it, const T& value);
void reverse();
T front() const;
T back() const;
int getSize() const;
private:
Node<T>* head;
Node<T>* tail;
int size;
bool isReverse;
//void insert_reverse(iterator it, const T& value);
};
๊น ์ด์์ ์์ฑํ๋๋ก ๋จผ์ , ๊ตฌํํ ๋ชฉ๋ก์ ์์ฑํ์ต๋๋ค.
๊ฐ ๊ธฐ๋ฅ์ ๋ํด์๋ ๋ช ๋ช ๋ถ๋ถ๋ง ์์ฑํ๋ ค๊ณ ํฉ๋๋ค.
๋จ์ ๋ถ๋ถ์ ๊ฐ์ ์์ฑํด๋ณด๊ณ ๋ชจ๋ฅด๊ฒ ์ผ๋ฉด ์ ๊นํ๋ธ์์ ํ์ธํ์๋ฉด ๋๊ฒ ์ต๋๋ค.
๊น ํ๋ธ ๋งํฌ๋ ์ ์ผ ํ๋จ์ ๊ณต๊ฐํ๊ฒ ์ต๋๋ค.
โป ์๋ฉด ์ข์ ๊ฐ๋
1. head์ tail
์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ๋ ์์ ๋ ธ๋์ ๋ ๋ ธ๋๋ก ๊ตฌ์ฑ๋์ด ์์ผ๋ฉฐ ์์๋ ธ๋ ๋ถํฐ ๋ ๋ ธ๋๊น์ง ์ฐ๊ฒฐ๋์ด์๋ค..
๋จ์ผ ์ฐ๊ฒฐ ๋ฆฌ์คํธ์์๋ ๋จ๋ฐฉํฅ์ผ๋ก๋ง ํ์์ ์งํํ ์ ์์์ง๋ง,
์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ์์๋ ์๋ฐฉํฅ์ผ๋ก ํ์์ ์งํํ ์ ์์ผ๋ฏ๋ก tail๋ถํฐ head๊น์ง๋ ํ์์ ์งํํ ์ ์๋ค.
2. iterator ๋ด๋ถ ํด๋์ค
์ฐ๋ฆฌ๊ฐ STL์ ์ฌ์ฉํ๋ค๋ณด๋ฉด ์๋์ ๊ฐ์ ์ฝ๋๋ฅผ ์ ํด๋ณธ ์ ์ด ์์ ๊ฒ์ด๋ค.
list<int> lis;
lis.push_back(1);
lis.push_back(2);
lis.push_back(3);
// ์๊ธฐ ์๊ธฐ ์๋ณด์ธ์ฐ
for(auto it = lis.begin(); it != lis.end(); it++) {
cout << *it << ' ';
}
it์ด๋ผ๊ณ ํ๋ฉด ๋ฌด์ธ๊ฐ๋ฅผ ์ง์นญํ๋ it์ด ์๋๋ค.
iterator์ ์ฝ์์ด๋ฉฐ auto๋ก ์๋ ์บ์คํ ๋๋ ์ ๋ถ๋ถ์ ์ฌ์ค 'list<int>::iterator' ๊ฐ ๋ค์ด๊ฐ๋ ๊ฒ์ด ์ณ๋ค.
์ฌ๊ธฐ์ '::' ๋ namespace์ ์ ๊ทผํ๋ ๊ฐ๋ ์ผ๋ก list ๋ด๋ถ์ iterator๋ผ๋ ๋ด๋ถ ํด๋์ค๊ฐ ์กด์ฌํ๋ ๊ฒ์ด๋ค.
๊ทธ๋ผ ์ฐ๋ฆฌ๋ ์ด iterator๋ฅผ ๊ตฌํํ๊ธฐ ์ํด์ ๋ด๋ถ ํด๋์ค๋ฅผ ์์ฑํด์ผ ํ๋ค.
์ต์ข ์ ์ผ๋ก DoublyLinkedList<int>::iterator ๋ก ๋ฐ์ดํฐ์ ๋ํ '๋ฐ๋ณต์'๋ฅผ ์ป์ ์ ์๋ค.
3. operator keyword
operator ํค์๋๋ ์ฐ๋ฆฌ๊ฐ ์ฌ์ฉํ๋ +=, ++, * ์ ๊ฐ์ ์ฐ์ฐ๊ธฐํธ๋ฅผ ์๋ฏธํ๋ค.
์ฐ๋ฆฌ๋ ํด๋์ค์์ ์ฐ์ฐ๊ธฐํธ์ ๋ํด์๋ ์ง์ ์์ ํ ์ ์๋ค.
๊ทธ ์ค operator++(int) ์ ๋ํด ์์์ผํ๋ค. ๋ฑ ๋ณด๋ฉด ํ์ ์ฐ์ฐ์ ์ฌ์ฉํ๋ ๊ฒ ๊ฐ์๋ฐ int๊ฐ ์์ฑ๋์ด์๋ค.
์ค์ ๋ก operator++(int)๋ ํ์์ฐ์ฐ์ ์์ฑํ๋๊ฒ ๋ง๊ณ , ์ ์ ์ฐ์ฐ์ ++operator๊ฐ ์๋๋ผ
operator++() ์ด๊ธฐ ๋๋ฌธ์ ์ด๋ฅผ ๊ตฌ๋ถํ๊ธฐ ์ํด int๋ฅผ ์์ฑํ์ต๋๋ค.
operator ํค์๋๋ก ์ฐ์ฐ๊ธฐํธ๋ฅผ ์ฌ์กฐ์ ํ๊ฒ ๋ค๋ ๋ป์ด ๋์ด์ผํ๋๋ฐ ++์ด๋ผ๋ ํค์๋๊ฐ ๋จผ์ ๋์ค๋ฉด ์ฐ์ฐ์ ํ๋ ค๊ณ ํ๊ฒ ์ฃ ? ์ฐ์ฐ์ ์ํํ ๋ค operator ํค์๋์ ์ ๊ทผํด๋ดค์ ์ฌ๋ณผ์๋ฌ๊ฐ ๋ฐ์ํ ๊ฒ ์ ๋๋ค.
4. isReverse ๋ณ์
SLT list๋ฅผ ์ฌ์ฉํด๋ณด์ ๋ถ๋ค ๊ณต๊ฐํ์ค ๊ฒ ๊ฐ์๋ฐ iterator๋ฅผ ๊ฐ์ ธ์ค๊ณ reverse๋ฅผ ํ๋ฉด ์ด๋ป๊ฒ ๋์ง?
list<int> l;
l.push_back(1); // null <- 1 -> null
l.push_back(2); // null <- 1 <-> 2 -> null
l.push_back(3); // null <- 1 <-> 2 <-> 3 -> null
auto it = l.begin(); // null <- 1(it) <-> 2 <-> 3 -> null
l.reverse(); // null <- 3 <-> 2 <-> 1(it) -> null
1. ๋งจ ์์์ ๊ฐ์ ธ์จ ์ ๋ณด๋ฅผ reverse ํ๊ฒ ๋๋ค๋ฉด ํด๋น iterator๋ ๋งจ ๋ง์ง๋ง์ ๊ฐ๋ฅดํค๋์ง?
2. ์ฌ์ ํ ๋งจ ์์ ๋ ์์ ๊ฐ๋ฅดํค๋์ง?
3. ๋งจ ๋ง์ง๋ง์ ๊ฐ๋ฅดํจ๋ค๊ณ ํ๋๋ผ๋ ++ ์ฐ์ฐ์ ํ๋ฉด null๋ก ์ด๋ํ๋์ง? 2๋ก ์ด๋ํ๋์ง?
๊ถ๊ธํ ๋ด์ฉ ์๋๊ฐ์??
์ ๋ reverse()๋ฅผ ํ๊ธฐ์ ์ iterator๋ ๋ด๋ถ ํด๋์ค ์ด๋ฆ์ iterator๋ก ์ฌ์ฉํ๊ณ
reverse์ ๊ดํ๊ฑด iterator2๋ reverseIterator ์ฒ๋ผ reverse ์ , ํ์ iterator๋ค์ ๊ด๋ฆฌํ๋ ํด๋์ค๊ฐ ๋ฐ๋ก ์์ ๊ฒ์ด๋ผ๊ณ ์๊ฐํ์ต๋๋ค. ๊ทธ๋์ list์์ ์ง์ ํ ์คํธ ํด๋ดค์ต๋๋ค.
list<int> l = {1, 2, 3};
list<int>::iterator it = l.begin(); // 1์ ๊ฐ๋ฅดํด
it++; // ๋ฌธ์ ์์ 2๋ฅผ ๊ฐ๋ฅดํด
l.reverse();
cout << *it; // ์ฌ์ ํ 2๋ฅผ ๊ฐ๋ฅดํด
// ์ฌ๊ธฐ์ it์ ๋ฐ์ดํฐ ๊ทธ ์์ฒด์ ๋ํ ์ ๋ณด๋ฅผ ๊ณ์ ๊ฐ์ง๊ณ ์์์ ์
cout << *(++it); // 1์ ๊ฐ๋ฅดํด !!!
// reverse ์ ์ ๋ฝ์ iter์.
// ํ์ง๋ง ++ ์ฐ์ฐ์ ํ๋ reverse ๊ฒฐ๊ณผ๊ฐ ์ ์ฉ ๋จ
// reverse๋ฅผ ํ์ง ์์๋ค๋ฉด ์๋ 3์ ๊ฐ๋ฅด์ผ์ผ ํจ!!!
// ์ฌ๊ธฐ์ it๋ reverse๊ฐ ๋๋๊ตฌ๋๋ฅผ ์๊ฒ ๋จ.
// ์๋ฌธ, ๊ทธ๋ผ reverse ์ , ํ์ ๋ด๋ถ ํด๋์ค iterator๊ฐ ๊ฐ์๊ฐ?
list<int>::iterator reverseIt = it.begin(); // 3์ ๊ฐ๋ฅดํด
// reverse ๋์์์๋ ๊ฐ์ iterator๋ฅผ ๋ฐํํจ.
๋ค์๊ณผ ๊ฐ์ ์ ๋ณด๋ก ๊ฐ์ iterator๋ฅผ ํตํด์ reverse ๋์๋์ง ๋ด๋ถ์ ์ผ๋ก ํต์ ํ๊ณ ์๋ค๊ณ ์๊ฐํ์ต๋๋ค.
๊ทธ๋์ ์์ฑ์์ ๋ํ ๋งค๊ฐ๋ณ์๋ก ์ฃผ์๊ฐ์ ์ ๋ฌํด์ฃผ๊ณ isReverse ๊ฐ์ ๋ฐ๋ผ reverse๋ ๊ฒฐ๊ณผ๋ฅผ ์ค์ผ๊ฒ ๋ค! ๋ผ๋ ์ ๊ทผ~
6. friend access modifier
private์ผ๋ก ์ค์ ํ ๋ฉค๋ฒ ๋ณ์ ๋ฐ ๋ฉ์๋๋ ์ธ๋ถ์์ ์ ๊ทผํ ์ ์์ต๋๋ค.
freind ์ ๊ทผ์ ํ์๋ฅผ ์ฌ์ฉํ๋ฉด ์น๊ตฌ๋ก ์ธ์ ํ๊ณ ๋ด๋ถ ์ ๋ณด์ ์ ๊ทผํ ์ ์๋๋ก ํด์ค๋๋ค.
์์ ๊ฐ๋ ์์ ์ฌ์ฉ๋๋ protected์๋ ๋ค๋ฆ ๋๋ค.
ํด๋น API์๋ erase ๋ฉ์๋๋ฅผ ๊ตฌํํ๊ธฐ ์ํด์๋ผ๋ฉด friend ์ ๊ทผ์ ํ์๊ฐ ํ์ํ๋ค๊ณ ์๊ฐํด์ ์ถ๊ฐํ์ต๋๋ค.
(์ฌ์ค ๋ง๋ค๋ค๋ณด๋ friend ์์ด๋ ์๋ ๊ฒ ๊ฐ์์ ์ถ๊ฐํจ..)
iterator ๊ตฌํ
template <typename T>
DoublyLinkedList<T>::iterator::iterator(Node<T>* node, bool& isReverse) : it(node), isReverse(isReverse) {}
template <typename T>
T DoublyLinkedList<T>::iterator::operator*() const {
return it->getData();
}
template <typename T>
typename DoublyLinkedList<T>::iterator& DoublyLinkedList<T>::iterator::operator++(int) {
if(isReverse) {
it = it -> getPrev();
} else {
it = it->getNext();
}
return *this;
}
template <typename T>
bool DoublyLinkedList<T>::iterator::operator!=(const iterator& other) const {
return it != other.it;
}
์์ฑ์, ํฌ์ธํฐ, ํ์์ฐ์ฐ, ๋น๊ต์ฐ์ฐ์ ๋ํ ์ฝ๋์ด๋ค.
๊ธฐ๋ฅ ๋จ์๋ก ๋๋ฌด ์์๊ฒ ์ ์์ฑํ ๊ฒ ๊ฐ์์ ใ ใ .. ์ค๋ช ์ ์๋ต
DoublyLinkedList Method
template <typename T>
DoublyLinkedList<T>::DoublyLinkedList() : head(nullptr), tail(nullptr), size(0), isReverse(false) {}
template <typename T>
typename DoublyLinkedList<T>::iterator DoublyLinkedList<T>::begin() {
return iterator(head, this -> isReverse);
}
template <typename T>
typename DoublyLinkedList<T>::iterator DoublyLinkedList<T>::end() {
return iterator(nullptr, this -> isReverse);
}
template <typename T>
void DoublyLinkedList<T>::push_back(const T& value) {
Node<T>* node = new Node<T>(value);
if (head == nullptr) {
head = node;
tail = node;
} else {
tail -> setNext(node);
node -> setPrev(tail);
tail = node;
}
size++;
}
๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ๊ธฐ๋ฅ์ธ push_back๊ณผ ํ์์ ์ํ, begin(), end()๋ฅผ ์ถ๊ฐํด๋ณด์๋ค.
ํ์ฉํ๊ธฐ
/*
authored by dot
https://dev-dot.tistory.com
*/
#include <list>
#include <iostream>
#include "DoublyLinkedList.h"
using namespace std;
int main() {
DoublyLinkedList<int> customList;
printf("push_back : 40, 50, 60\n");
customList.push_back(40);
customList.push_back(50);
customList.push_back(60);
printf("push_front : 30, 20, 10\n");
customList.push_front(30);
customList.push_front(20);
customList.push_front(10);
printf("pop_front\n");
customList.pop_front();
printf("pop_back\n\n");
customList.pop_back();
printf("begin() and rbegin() before reverse\n");
printf("begin val : %d, rbegin val : %d\n", *(customList.begin()), *(customList.rbegin()));
printf("front() and back() before reverse\n");
printf("front : %d, back : %d\n", customList.front(), customList.back());
printf("Forward Travel\n");
for(auto it = customList.begin(); it != customList.end(); it++) {
cout << *it << ' ';
}
cout << "\n\n";
customList.reverse();
printf("begin() and rbegin() after reverse\n");
printf("begin val : %d, rbegin val : %d\n", *(customList.begin()), *(customList.rbegin()));
printf("front() and back() before reverse\n");
printf("front : %d, back : %d\n", customList.front(), customList.back());
printf("Reversed Travel\n");
for(auto it = customList.begin(); it != customList.end(); it++) {
cout << *it << ' ';
}
cout << "\n\n";
DoublyLinkedList<int>::iterator it = customList.begin();
it++;
printf("value of it : %d\n", *it);
it = customList.erase(it);
printf("value of it after erase : %d\n", *it);
it = customList.erase(customList.begin());
printf("value of it after erase front : %d\n", *it);
it++;
it = customList.erase(it);
printf("value of it after erase back : %d\n", *it);
printf("Travel after erase\n");
for(auto it = customList.begin(); it != customList.end(); it++) {
cout << *it << ' ';
}
cout << "\n\n";
customList.insert(it, 20);
printf("Travel after insert\n");
for(auto it = customList.begin(); it != customList.end(); it++) {
cout << *it << ' ';
}
cout << "\n\n";
return 0;
}
์คํ ๊ฒฐ๊ณผ
๋ชจ๋ ๊ธฐ๋ฅ์ด ์์ฑ๋ ์ฝ๋๋ Github ๋ ํ์งํ ๋ฆฌ์ push ํ ์์ ์ ๋๋ค.
๋ค๋ฅธ ๊ธฐ๋ฅ๋ค์ ํ ๋ฒ ์ง์ ๊ตฌํํด๋ณด์๋๊ฑธ ์ถ์ฒ๋๋ฆฝ๋๋ค.
์! ๊ทธ๋ฆฌ๊ณ ํน์ ์ด๊ธ์ ๋ณด์๋ ๋ถ๋ค ์ค Readme.md๋ฅผ ๊พธ๋ฉฐ์ฃผ์๊ฑฐ๋...
๋ถ์กฑํ ๋ฉ์๋๋ฅผ ์ฑ์์ PR ํด์ฃผ์๋ฉด ์ ๋ง ๊ฐ์ฌํ๊ฒ ์ต๋๋ค!!!
์์ฑํด๋ณด๋ฉด ๋์์ด ๋๋ Method
reverse, erase, push_front ๋ ํ์๋ก ํด๋ณด์๋ฉด ์ข๊ฒ ์ต๋๋ค.
erase์ ๊ฒฝ์ฐ ์ฃผ์ํด์ผ ํ ์ ์ด ๋ง์ต๋๋ค!
๊นํ๋ธ ์ด์ ๋ฐ ๋ ํ์งํ ๋ฆฌ, ๋ ํผ๋ฐ์ค
๊นํ๋ธ ์ด์ : https://github.com/jihwankim128/datastructure/issues/4
์ด์ค ์ฐ๊ฒฐ ๋ฆฌ์คํธ (Doubly Linked List) · Issue #4 · jihwankim128/datastructure
https://cplusplus.com/reference/list/list/ STL list ๋ฐ๋ผ์ก๊ธฐ iterators: begin end rbegin rend Capacity: empty size elemental : front back modifiers: push_back push_front pop_back pop_front insert erase...
github.com
๊นํ๋ธ ๋ ํ์งํ ๋ฆฌ : https://github.com/jihwankim128/datastructure
GitHub - jihwankim128/datastructure
Contribute to jihwankim128/datastructure development by creating an account on GitHub.
github.com
๋ ํผ๋ฐ์ค : https://cplusplus.com/reference/list/list/insert/
https://cplusplus.com/reference/list/list/insert/
range (3)template iterator insert (const_iterator position, InputIterator first, InputIterator last);
cplusplus.com
'์๊ณ ๋ฆฌ์ฆ > ์๋ฃ๊ตฌ์กฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
6. STL ์ฌ์ฉํ๊ธฐ - std::list (0) | 2024.02.11 |
---|---|
5. ์ํ ์ฐ๊ฒฐ ๋ฆฌ์คํธ (Circular Linked List) (1) | 2024.02.10 |
3. STL ๋ฐ๋ผ์ก๊ธฐ - ๋จ์ ์ฐ๊ฒฐ ๋ฆฌ์คํธ (Singly Linked List) ๊ตฌํ (0) | 2024.02.04 |
2. ์ฐ๊ฒฐ ๋ฆฌ์คํธ (Linked List) (1) | 2024.02.04 |
1. ์๋ฃ๊ตฌ์กฐ๋? (2) | 2024.01.26 |