[Implemented] Exchange Elements (linked list sort)
Posted: Sun Nov 10, 2002 2:41 pm
Restored from previous forum. Originally posted by horst.
This is a Linked List (bubble) sort I made for a special
reason (see below). For the same reason I made a separate
procedure to exchange an element with the previous one.
(Implemented with 'SwapElements()')
The structure has only one string in it. When you need
more, you will have to exchange all fields of the structure
in the procedure ExchangeWithPreviousElement()
It would be extremely helpful if we had a PB function
"ExchangeWithPreviousElement()", which modifies only the
pointers. No data would have to be changed or moved around,
and no elements were deleted and inserted.
Actually, that's what linked lists are all about..
The function would also be helpful to move an element
up or down in a linked list.
Fred?? Pleeeeez
Horst
This is a Linked List (bubble) sort I made for a special
reason (see below). For the same reason I made a separate
procedure to exchange an element with the previous one.
(Implemented with 'SwapElements()')
Code: Select all
Structure ll
name.s
EndStructure
NewList List.ll()
Procedure ExchangeWithPreviousElement()
name1.s = List()\name
PreviousElement(List())
name2.s = List()\name
List()\name = name1
NextElement(List())
List()\name = name2
EndProcedure
Procedure SortList()
last = CountList(List()) -1
While last >= 1
FirstElement(list()) : uptodo = 0
name.s = List()\name
For i = 1 To last
NextElement(List())
If name <= List()\name
name = List()\name
Else
ExchangeWithPreviousElement()
uptodo = i-1
EndIf
Next
last = uptodo
Wend
EndProcedure
more, you will have to exchange all fields of the structure
in the procedure ExchangeWithPreviousElement()

It would be extremely helpful if we had a PB function
"ExchangeWithPreviousElement()", which modifies only the
pointers. No data would have to be changed or moved around,
and no elements were deleted and inserted.
Actually, that's what linked lists are all about..
The function would also be helpful to move an element
up or down in a linked list.
Fred?? Pleeeeez
Horst