내가 무식한건가?ㅎㅎ 템플릿 링크드 리스트 는?ㅎㅎ
- 프로그래밍언어/programming JPA
- 2016. 8. 5. 13:42
// 예전에 멋도 멋도 모르구..마구잡이로 작성한 리스트 ... 그저 한숨만쉬는? ㅋㅋ
// 그냥 벡터 쓰는게 낳을지도몰랐던거라는 뒤늦은 후회중?이라할까
template <typename T>
struct T_Link
{
T temp;
int id;
T_Link* link;
};
template <typename T>
class Temp_Link //링크드 리스트를 관리하는 함수
{
private:
T_Link<T>* back_link;
int linkMax;
public:
T_Link<T>* t_link;
public:
Temp_Link(T temp);
Temp_Link();
//void NextLink();
bool NextLink();
bool NextLink(int _num);
bool SerchId(int _id);
bool SerchIdFree(int _id);
void AddLink(T _temp);
void AddLinkA(T _temp);
void AddLink(T _temp,int _id);
void AddLinkA(T _temp,int _id);
void ReSet(){t_link = back_link;}
T& GetLink(){return t_link;}
};
template <typename T>
bool Temp_Link<T>::SerchIdFree(int _id)
{
T_Link<T>* tmp_link=NULL;
T_Link<T>* back_link=NULL;
while(t_link){
if(t_link->id == _id){
tmp_link=t_link->link;
if(back_link==NULL){
free(t_link);
t_link=tmp_link;
}
else back_link->link = tmp_link;
}
back_link = t_link;
t_link = t_link->link;
}
ReSet();
return false;
}
template <typename T>
bool Temp_Link<T>::SerchId(int _id)
{
while(t_link)
{
if(t_link->id == _id) return true;
t_link = t_link->link;
}
return false;
}
template <typename T>
Temp_Link<T>::Temp_Link(T _temp)
{
t_link = new T_Link<T>;
t_link->link=NULL;
linkMax = 0;
id = 0;
back_linkA = t_linkA;
}
template <typename T>
Temp_Link<T>::Temp_Link()
{
t_link = new T_Link<T>;
t_link->link=NULL;
back_link = t_link;
}
template <typename T>
void Temp_Link<T>::AddLink(T _temp) // 링크를 추가 합니다,.
{
T_Link<T>* temp_link = new T_Link<T>;
temp_link->link = NULL;
temp_link->link = t_link;
t_link = temp_link;
t_link->temp = _temp;
back_link = t_link; //백업 링크
linkMax++;
}
template <typename T>
void Temp_Link<T>::AddLink(T _temp,int _id) // 링크를 추가 합니다,. //아이디 추가
{
T_Link<T>* temp_link = new T_Link<T>;
temp_link->link = NULL;
temp_link->link = t_link;
t_link = temp_link;
t_link->temp = _temp;
t_link->id = _id;
back_link = t_link; //백업 링크
linkMax++;
}
template <typename T>
void Temp_Link<T>::AddLinkA(T _temp) // 순서대로 링크를 추가 합니다,.
{
T_Link<T>* temp_link = new T_Link<T>;
temp_link->link = NULL;
while(t_link->link!=NULL){t_link=t_link->link;}
t_link->link = temp_link;
t_link->temp = _temp;
t_link = back_link;
linkMax++;
}
template <typename T>
void Temp_Link<T>::AddLinkA(T _temp,int _id) // 순서대로 링크를 추가 합니다,. //id 추가
{
T_Link<T>* temp_link = new T_Link<T>;
temp_link->link = NULL;
while(t_link->link!=NULL){t_link=t_link->link;}
t_link->link = temp_link;
t_link->temp = _temp;
t_link->id = _id;
t_link = back_link;
linkMax++;
}
template <typename T>
bool Temp_Link<T>::NextLink()
{
t_link=t_link->link;
if(t_link->link== NULL){ t_link = back_link; return false;}
else return true;
}
template <typename T>
bool Temp_Link<T>::NextLink(int _num) //0부터 시작합니다~
{
if(_num>linkMax-1) return false;
t_link=back_link;
for(int i=0;i<_num;i++)
t_link=t_link->link;
return true;
}
'프로그래밍언어 > programming JPA' 카테고리의 다른 글
프로그래밍의 기초 (36) | 2017.01.23 |
---|---|
C언어 시작 프로그래밍 기본 요소는? (12) | 2016.10.25 |
프로그래밍 C 변수정의는? (4) | 2016.08.05 |
(Google) Guava CacheBuilder의 concurrencyLevel( ) (3) | 2016.06.05 |
프로그래밍 언어의 종류와 용도는? (22) | 2016.05.07 |
(Java)자바 순환 Q (Circular Queue)? (10) | 2015.12.11 |