我試圖爲我的大學項目實現佈雷排序,並且我有一些問題。 如果你能幫助我,我會很高興。C++中的鏈表的氣泡排序
void TrainManagerLinkedList:: Swap(TrainManager & x,TrainManager & y)
{
TrainManager temp;
temp =x;
x = y;
y = temp;
}
void TrainManagerLinkedList::BubbleSort()
{
TrainManagerLink* outerCurr = this->m_head;
TrainManagerLink* curr = NULL;
while(outerCurr != NULL)
{
curr = this->m_head;
while(curr != NULL && curr->m_next != NULL)
{
/*if the current link greater then the next swap between them*/
if (curr->m_data->GetDate() > curr->m_next->m_data->GetDate())
{
Swap(&(curr->m_data),&(curr->m_next->m_data));
}
else if((curr->m_data->GetDate() == curr->m_next->m_data->GetDate())&(curr->m_data->GetTime() > curr->m_next->m_data->GetTime()))
{
Swap(&(curr->m_data),&(curr->m_next->m_data));
}
curr = curr->m_next;
}
outerCurr = outerCurr->m_next;
}
/*now the list is sorted :)*/
}
我的數據類型
TrainManagerLink *m_head;
TrainManagerLink *m_tail;
int m_numOfElements;
class TrainManager
{
char * m_firstStation;
char *m_lastStation;
char * m_origin;
char * m_destination;
int m_timeBetweenStations;
Hour m_releaseTime;
Hour m_arriveTime;
Hour m_firstHour;
Date m_Date;
int m_standInstation;
DelayersLinkedList delay;
}
鏈表應該由日期和時間進行排序。 但我有一些編譯問題。 我還需要你的幫助 謝謝,:)
你能將所有代碼格式化爲代碼嗎?謝謝! – 2010-12-21 09:32:28
什麼是編譯器錯誤的確切用詞? – 2010-12-21 09:34:02
此問題缺少相當多的上下文信息。請閱讀[「關於您的問題的準確性和內容豐富性」](http://www.catb.org/~esr/faqs/smart-questions.html#beprecise),[「詢問代碼時」](http:/ /www.catb.org/~esr/faqs/smart-questions.html#code)和[「寫出完美的問題」](http://tinyurl.com/so-hints)。 – outis 2010-12-21 09:42:53