Answer the question
In order to leave comments, you need to log in
How to sort a dynamic list?
I have a dynamic list (TSpisok) that has a name, a price and a diagonal. How can I sort this list by diagonal size? Only through an array?
type
TPSpisok=^TSpisok; //указатель на тип TSpisok
TSpisok = record
name:string[20]; // имя
price: string[20]; // цена
diagonal: string[20]; // диагональ
next: TPSpisok; // следующий элемент списка
end;
var
head: TPSpisok; // начало (голова) списка
// добавить элемент в начало списка
procedure TForm1.Button1Click(Sender: TObject);
var
curr: TPSpisok; // новый элемент списка
begin
new(curr); // выделить память для элемента списка
curr^.name:= Edit1.Text;
curr^.price:= Edit2.Text;
curr^.diagonal:= Edit3.Text;
// добавление в начало списка
curr^.next := head;
head := curr;
// очистить поля ввода
Edit1.text:='';
Edit2.text:='';
Edit3.text:='';
end;
Answer the question
In order to leave comments, you need to log in
What a horror, why keep a diagonal in a row ...
On the case.
Outer enumeration of all elements from the first to the last
. Inside, it is also enumeration from the element on which the outer iteration is located and to the last one,
if the diagonal_of_the_external_enumeration < the diagonal_of_the_external_enumeration_on_the_external_enumeration - swap them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question