千月星跡
アイをも求めて彷徨っている孤独なヒーロー
登录
注册
全站
当前博客
空间
博客
好友
相册
留言
last_impression
ID:Last_Impression
共
11773
次访问,排名
9339
好友
0
人,关注者
3
人
Last_Impression的文章
原创 52 篇
翻译 3 篇
转载 76 篇
评论 1 篇
最近评论
mohroq:
wow gold
,
文章分类
C++
(RSS)
C++设计模式(QT)
(RSS)
C语言
(RSS)
Qt
(RSS)
Ruby
(RSS)
VB语言
(RSS)
VC++多线程应用
(RSS)
YACC
(RSS)
测试&&品质
(RSS)
设计模式
(RSS)
孙鑫VC++
(RSS)
系统分析师-论文
(RSS)
收藏
相册
存档
2008年08月(2)
2008年07月(5)
2008年06月(1)
2008年05月(31)
2008年04月(11)
2008年03月(7)
2008年02月(8)
2008年01月(18)
2007年12月(12)
2007年10月(7)
2007年09月(8)
2007年08月(21)
订阅我的博客
VC++多线程应用--代码清单二:链表
收藏
新一篇: VC++多线程应用--代码清单三:事件TASK
|
旧一篇: VC++多线程应用--代码清单一:节点
#ifndef _NOTE_H
#define
_NOTE_H
#pragma
once
#include
"
.TokenElement.h
"
class
__declspec(dllexport) CNote
...
{
public
:
CNote();
~
CNote();
public
:
US key;
CNote
*
header_p;
CNote
*
tail_p;
CTokenElement
*
element_p;
}
;
#endif
#ifndef _LINKLIST_H
#define
_LINKLIST_H
#pragma
once
#include
"
.EventDefine.h
"
#include
"
.Note.h
"
class
__declspec(dllexport) CLinkList
...
{
public
:
CLinkList(
void
)
...
{ rootnote_p
=
NULL; }
;
virtual
~
CLinkList(
void
)
...
{}
;
virtual
void
Remove(CNote
*
)
=
0
;
virtual
bool
GetHeader(CNote
**
)
=
0
;
virtual
void
Free(
void
)
=
0
;
protected
:
CNote
*
rootnote_p;
}
;
#endif
/* _LINKLIST_H */
循环链表
#ifndef _CIRCULARLINKLIST_H
#define
_CIRCULARLINKLIST_H
#pragma
once
#include
"
.LinkList.h
"
class
__declspec(dllexport) CCircularLinkList
: CLinkList
...
{
public
:
CCircularLinkList(
void
);
~
CCircularLinkList(
void
);
/**/
/*
インサートheader
*/
void
InsertHeader(CTokenElement
*
);
/**/
/*
アペンドtail
*/
void
AppendTail(CTokenElement
*
);
/**/
/*
探す
*/
bool
Search(CTokenElement
*
, CNote
**
);
bool
Search(OBJECT, CNote
**
);
/**/
/*
削除
*/
void
Remove(CNote
*
);
void
Remove(CTokenElement
*
);
void
Remove(OBJECT);
/**/
/*
GetNext
*/
CNote
*
GetNext(CNote
*
);
/**/
/*
GetPrevious
*/
CNote
*
GetPrevious(CNote
*
);
/**/
/*
GetHeader
*/
bool
GetHeader(CNote
**
);
/**/
/*
GetTail
*/
bool
GetTail(CNote
**
);
/**/
/*
押し込み
*/
void
PushIn(CNote
*
);
/**/
/*
押し出し
*/
void
PullOut(CNote
*
);
/**/
/*
解放
*/
void
Free(
void
);
}
;
#endif
/* _CIRCULARLINKLIST_H */
#include
"
StdAfx.h
"
#include
"
.CircularLinkList.h
"
CCircularLinkList::CCircularLinkList(
void
)
...
{
}
CCircularLinkList::
~
CCircularLinkList(
void
)
...
{
Free();
}
/**/
/*
node input linklist
*/
void
CCircularLinkList::InsertHeader(CTokenElement
*
element_p)
...
{
CNote
*
note_p;
note_p
=
new
CNote();
if
(NULL
==
rootnote_p)
...
{
rootnote_p
=
note_p;
note_p
->
header_p
=
note_p;
note_p
->
tail_p
=
note_p;
note_p
->
element_p
=
element_p;
}
else
...
{
note_p
->
header_p
=
rootnote_p
->
header_p;
note_p
->
tail_p
=
rootnote_p;
note_p
->
element_p
=
element_p;
rootnote_p
->
header_p
->
tail_p
=
note_p;
rootnote_p
->
header_p
=
note_p;
/**/
/*
give head note
*/
rootnote_p
=
note_p;
}
}
void
CCircularLinkList::AppendTail(CTokenElement
*
element_p)
...
{
CNote
*
note_p;
note_p
=
new
CNote();
if
(NULL
==
rootnote_p)
...
{
rootnote_p
=
note_p;
note_p
->
header_p
=
note_p;
note_p
->
tail_p
=
note_p;
note_p
->
element_p
=
element_p;
}
else
...
{
note_p
->
header_p
=
rootnote_p
->
header_p;
note_p
->
tail_p
=
rootnote_p;
note_p
->
element_p
=
element_p;
rootnote_p
->
header_p
->
tail_p
=
note_p;
rootnote_p
->
header_p
=
note_p;
}
}
bool
CCircularLinkList::Search(CTokenElement
*
element_p, CNote
**
node_dp)
...
{
bool
result;
CNote
*
note_p;
OBJECT instance_p;
result
=
false
;
instance_p
=
element_p
->
Get();
if
(NULL
!=
rootnote_p)
...
{
note_p
=
rootnote_p;
while
(NULL
!=
note_p)
...
{
/**/
/*
check node value
*/
if
(instance_p
==
note_p
->
element_p
->
Get())
...
{
*
node_dp
=
note_p;
result
=
true
;
break
;
}
/**/
/*
get next
*/
note_p
=
rootnote_p
->
tail_p;
/**/
/*
one circle passed
*/
if
(rootnote_p
==
note_p)
...
{
break
;
}
}
}
return
result;
}
bool
CCircularLinkList::Search(OBJECT object_p, CNote
**
node_dp)
...
{
CNote
*
note_p;
bool
result
=
false
;
if
(NULL
!=
rootnote_p)
...
{
note_p
=
rootnote_p;
while
(NULL
!=
note_p)
...
{
if
(object_p
==
note_p
->
element_p
->
Get())
...
{
*
node_dp
=
note_p;
result
=
true
;
break
;
}
/**/
/*
get next
*/
note_p
=
rootnote_p
->
tail_p;
/**/
/*
one circle passed
*/
if
(note_p
==
rootnote_p)
...
{
break
;
}
}
}
return
result;
}
void
CCircularLinkList::Remove(CNote
*
note_p)
...
{
if
(NULL
!=
note_p
&&
NULL
!=
rootnote_p)
...
{
if
(note_p
==
rootnote_p)
...
{
if
(note_p
==
rootnote_p
->
tail_p)
...
{
rootnote_p
=
NULL;
}
else
...
{
rootnote_p
->
header_p
->
tail_p
=
note_p
->
tail_p;
rootnote_p
->
tail_p
->
header_p
=
note_p
->
header_p;
rootnote_p
=
note_p
->
tail_p;
}
}
else
...
{
note_p
->
header_p
->
tail_p
=
note_p
->
tail_p;
note_p
->
tail_p
->
header_p
=
note_p
->
header_p;
}
/**/
/*
remove the node
*/
delete note_p
->
element_p;
delete note_p;
}
}
void
CCircularLinkList::Remove(CTokenElement
*
element_p)
...
{
CNote
*
note_p;
if
( Search(element_p,
&
note_p) )
...
{
Remove(note_p);
}
}
void
CCircularLinkList::Remove(OBJECT object_p)
...
{
CNote
*
note_p;
if
( Search(object_p,
&
note_p) )
...
{
Remove(note_p);
}
}
CNote
*
CCircularLinkList::GetNext(CNote
*
node_p)
...
{
return
node_p
->
tail_p;
}
CNote
*
CCircularLinkList::GetPrevious(CNote
*
node_p)
...
{
return
node_p
->
header_p;
}
bool
CCircularLinkList::GetHeader(CNote
**
node_dp)