[STL ] map 會自動在最前面加空資料???
我宣告了一個
STL的map 裡面的資料是擺一個struct
而我每加一筆資料到map裡時
會用minHeap排序 依照struct 裡面的某個float 的大小排序
可是當我在比較map中的某兩個位置的 struct 中的某個float 的大小時
系統卻會常常會自動在我的map陣列的最前面加入兩個或一個都是 0 的資料
而且之後也不會自動刪除
以下是我的部份程式碼
struct Node
{
int verID1;
int verID2;
float curCost;
float heuristic;
Node *parent;
};
inline DWORD GetKey( int verID1, int verID2 )
{
return ( MAKELONG( verID1, verID2 ));
}
inline int GetHeapParent( int i )
{
return ((i+1)/2-1);
}
map <DWORD, Node> closelist;
void Astar::InsertMinHeap( Node n)
{
closelist.insert( map< DWORD, Node>::
value_type( GetKey( n.verID1 ,n.verID2 ), n));
int curPose=closelist.size()-1;
while(TRUE)
{
int i=GetHeapParent( curPose );
if(i==-1)
break;
if((closelist[curPose].curCost+closelist[curPose].heuristic)<
(closelist[i].curCost+closelist[i].heuristic))
{
Node buf=closelist[curPose];
closelist[curPose]=closelist[i];
closelist[i]=buf;
curPose=i;
}
else
break;
}
}
就是下面這兩行
"" if((closelist[curPose].curCost+closelist[curPose].heuristic)<
(closelist[i].curCost+closelist[i].heuristic)) ""
常常會都自動再幫我加兩個或一個 資料都為0的map 而且加在最前面
希望大家可以看的懂
麻煩大家了 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 60.248.163.42
推
08/23 08:11, , 1F
08/23 08:11, 1F
→
08/23 13:10, , 2F
08/23 13:10, 2F
→
08/23 13:18, , 3F
08/23 13:18, 3F
→
08/23 13:21, , 4F
08/23 13:21, 4F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 3 篇):
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章