按降序对链表进行排序

时间:2016-11-24 01:54:48

标签: c++ sorting linked-list text-files

我有一个函数可以将1000行插入到一个链表中,每行都会在结尾处插入。但我需要对其进行修改,以便根据行前面的数字按降序组织链表。但我真的很难弄清楚如何做到这一点...任何帮助将不胜感激!

void Term :: InsertAtEnd(string file, int size)
{
    struct node *temp, *temp_2;
    temp_2 = start;
    for (int i = 0; i < size; i++)
    {
        temp_2 = temp_2 -> next;
    }
    temp = new(node);
    temp -> text = file;
    if (temp_2 -> next == NULL)
    {
        temp_2 -> next = temp;
        temp -> next = NULL;
        temp -> prev = temp_2;      
    }
    else
    {
        temp -> next = temp_2 -> next;
        temp -> next -> prev = temp;
        temp_2 -> next = temp;
        temp -> prev = temp_2;
    }
}

0 个答案:

没有答案