我试图为我的大学项目实现布雷排序,并且我有一些问题。 如果你能帮助我,我会很高兴。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