Я попытался реализовать сортировку buble для моего университетского проекта, и у меня возникли некоторые проблемы.Я буду рад, если вы поможете мне с этим.
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;
}
связанный список должен быть отсортирован по дате и часам.но у меня есть некоторые проблемы с компиляцией.я действительно нуждаюсь в вашей помощи, спасибо, :)