http://kvodo.ru/linked-lists.html
Здесь создается двусвязный список. Скажите, как потом элементы этого списка можно сортировать после того как мы его создадим? В int main
создается список 5 7 3 9 2
. Реально его сортировать в этой же программе?
#include <iostream>
#include <cstdlib>
#include <string.h>
using namespace std;
struct DoubleList
{
int data;
DoubleList *next;
DoubleList *prev;
};
DoubleList *head;
void AddList(int value, int position)
{
DoubleList *node = new DoubleList;
node->data = value;
if (head == NULL)
{
node->next = node;
node->prev = node;
head = node;
}
else
{
DoubleList *p=head;
for(int i=position; i>1; i--) p = p->next;
p->prev->next=node;
node->prev = p->prev;
node->next = p;
p->prev = node;
}
cout<<"\nThe elemen is added\n\n";
}
int DeleteList(int position)
{
if (head == NULL) { cout<<"\nThe list is empty\n\n"; return 0; }
if (head == head->next)
{
delete head;
head = NULL;
}
else
{
DoubleList *a = head;
for (int i=position; i>1; i--) a = a->next;
if (a == head) head = a->next;
a->prev->next = a->next;
a->next->prev = a->prev;
delete a;
}
cout<<"\nThe list is deleted\n\n";
}
void PrintList()
{
if (head==NULL) cout << "Empty\n";
else
{
DoubleList *a=head;
cout << "\nElements: ";
do
{
cout << a->data << " ";
a = a->next;
} while(a != head);
cout << "\n\n";
}
}
int main(int argc, char** argv) {
AddList(5,1);
AddList(7,2);
AddList(3,3);
AddList(9,4);
AddList(2,5);
PrintList();
return 0;
}
Нужно максимально оптимизировать файловый выводНачал с обычной очереди сообщений и записи в отдельном потоке с предварительным форматированием
По ходу изучения предмета Алгоритмы и структуры данных, знакомлюсь с разными алгоритмами сортировки, конкретно с quick sort на данном этапе, задался...