Page 1 of 1

Posted: Tue May 28, 2002 6:21 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

If anyone is looking for a fairly simple way to sort LinkedLists, you can check out my snippet on the PB Resources Site. http://www.reelmediaproductions.com/pb

It's not the more optimized but it does the job :)
It is also fairly easy to adapt to your existing LinkedLists once you see what is going on.

Posted: Tue May 28, 2002 7:06 pm
by BackupUser
Restored from previous forum. Originally posted by Andre.
If anyone is looking for a fairly simple way to sort LinkedLists, you can check out my snippet on the PB Resources Site. http://www.reelmediaproductions.com/pb
Hi Paul, I would like to try it. But since the new layout of the site is used I can't download files anymore. There is no possibility to download files with right-mouse-click and choosing "Save as...", and when using left-mouse on the links "View" the download client gets started (have tried Gozilla and FreshDownload) and here is the problem: no file is saved correctly, every time (mostly at 99% download) there comes as disconnect while downloading and resume also failed.... Anyone, who have an idea ?


Regards
André

*** German PureBasic Support ***

Posted: Tue May 28, 2002 7:11 pm
by BackupUser
Restored from previous forum. Originally posted by Paul.

My first suggestion would be not to use download clients :)

A better suggestion though would be to double click on the filename you want to download. Information will pop up about that file... including the actually path were the file is located on the server.
You could copy and paste this path into your browser maybe?

Third suggestion would be to download the entire snippet package from the link at the top. You can still right click on that.

Good luck.

Posted: Tue May 28, 2002 10:27 pm
by BackupUser
Restored from previous forum. Originally posted by Pupil.
If anyone is looking for a fairly simple way to sort LinkedLists, you can check out my snippet on the PB Resources Site. http://www.reelmediaproductions.com/pb

It's not the more optimized but it does the job :)
It is also fairly easy to adapt to your existing LinkedLists once you see what is going on.
Good work Paul!

I felt rather inspired by Paul's effort so i had to give it a try myself and come up with this little piece of code, though mine isn't as nicely commented as Pauls it will hopefully not be too difficult to understand;) The code is based on the god old bubble sort algo so it isn't a speed freak... Enjoy!

Code: Select all

Structure testtype
  a.l
  b.l
  c.s
EndStructure


NewList testlist.testtype()

Declare SortLinkedList()

For i = 0 To 13
	Read tmpdata.s
	AddElement(testlist())
	testlist()\c = tmpdata
Next

SortLinkedList()
ResetList(testlist())
msg$ = "Content:"+Chr(10)
While NextElement(testlist())
	msg$ + testlist()\c + Chr(10)
Wend
MessageRequester("", msg$,0)

End

DataSection
	Data.s "f", "e", "d", "c", "b", "a", "qw", "jj", "da", "JJ", "lji", "QWW", "qw","aa"
EndDataSection


Procedure SortLinkedList()
	ResetList(testlist())
	NextElement(testlist())
	*listendsorted = testlist()
	If *listendsorted
		Repeat
			If NextElement(testlist())
				*listnext.testtype = testlist() ; Object to sort
				ResetList(testlist())
				quit = 0
				While quit = 0
					If NextElement(testlist())
						If testlist()\c > *listnext\c ; Sort criteria
							quit = 1
						ElseIf testlist() = *listendsorted
							quit = 2
						EndIf
					EndIf
				Wend
				If quit = 1
					InsertElement(testlist())
				ElseIf quit = 2
					AddElement(testlist())
					*listendsorted = testlist()
				EndIf
					testlist()\a = *listnext\a
					testlist()\b = *listnext\b
					testlist()\c = *listnext\c
					ChangeCurrentElement(testlist(), *listnext)
					DeleteElement(testlist())
			Else
				finished = 1
			EndIf
		Until finished = 1
	EndIf
EndProcedure


Edited by - Pupil on 28 May 2002 23:30:35

Edited by - Pupil on 29 May 2002 08:07:44

Posted: Wed May 29, 2002 9:20 am
by BackupUser
Restored from previous forum. Originally posted by Fangbeast.
If anyone is looking for a fairly simple way to sort LinkedLists, you can check out my snippet on the PB Resources Site. http://www.reelmediaproductions.com/pb

It's not the more optimized but it does the job :)
It is also fairly easy to adapt to your existing LinkedLists once you see what is going on.
Good work Paul!

I felt rather inspired by Paul's effort so i had to give it a try myself and come up with this little piece of code, though mine isn't as nicely commented as Pauls it will hopefully not be too difficult to understand;) The code is based on the god old bubble sort algo so it isn't a speed freak... Enjoy!

Code: Select all

Structure testtype
  a.l
  b.l
  c.s
EndStructure


NewList testlist.testtype()

Declare SortLinkedList()

For i = 0 To 13
	Read tmpdata.s
	AddElement(testlist())
	testlist()\c = tmpdata
Next

SortLinkedList()
ResetList(testlist())
msg$ = "Content:"+Chr(10)
While NextElement(testlist())
	msg$ + testlist()\c + Chr(10)
Wend
MessageRequester("", msg$,0)

End

DataSection
	Data.s "f", "e", "d", "c", "b", "a", "qw", "jj", "da", "JJ", "lji", "QWW", "qw","aa"
EndDataSection


Procedure SortLinkedList()
	ResetList(testlist())
	NextElement(testlist())
	*listendsorted = testlist()
	If *listendsorted
		Repeat
			If NextElement(testlist())
				*listnext.testtype = testlist() ; Object to sort
				ResetList(testlist())
				quit = 0
				While quit = 0
					If NextElement(testlist())
						If testlist()\c > *listnext\c ; Sort criteria
							quit = 1
						ElseIf testlist() = *listendsorted
							quit = 2
						EndIf
					EndIf
				Wend
				If quit = 1
					InsertElement(testlist())
				ElseIf quit = 2
					AddElement(testlist())
					*listendsorted = testlist()
				EndIf
					testlist()\a = *listnext\a
					testlist()\b = *listnext\b
					testlist()\c = *listnext\c
					ChangeCurrentElement(testlist(), *listnext)
					DeleteElement(testlist())
			Else
				finished = 1
			EndIf
		Until finished = 1
	EndIf
EndProcedure


Edited by - Pupil on 28 May 2002 23:30:35

Edited by - Pupil on 29 May 2002 08:07:44
Paul did his sort in response to a query I had and then helped me fix my mistakes whch I always make. If you are only going to sort a small number of items, say less than a thousand or so, even on a small machine, the following routine makes use of PB's arraysort routine to do things nice and fast.

Three cheers to Paul for inspiring me to think :):)

Code: Select all

Procedure SortCategories()

  Elements = 0                              ; Starting elements = 0
  
  Num = ListIndex(Cat())                    ; How many categories do we have to work on
  
  Dim CatSort.s(Num)                        ; Dimension the array witht eh number of categories
  
  ResetList(Cat())                          ; Reset the category list now
  
  While NextElement(Cat())                 ; Loop through elements, adding them to the array
    CatSort.s(Elements) = Cat()\category
    Elements + 1
  Wend
  
  SortArray(CatSort.s(), 2)                 ; Sort the string array
  
  ClearList(Cat())                          ; Clear the categories
  
  For Start = 0 To Elements - 1            ; Add the items back into the linked list
    AddElement(Cat())
    Cat()\category = CatSort.s(Start)
  Next Start
  
  Dim CatSort.s(0)                         ; Clear the temporary array
  
  ClearGadgetItemList(#CategoryTree)        ; Clear the category tree
  
  ReDisplayCat()                            ; Redisplay sorted category
  
EndProcedure
Fangles