A list of lists

Just starting out? Need help? Post your questions and find answers here.
two_bits
User
User
Posts: 15
Joined: Sat Oct 04, 2003 6:52 pm

A list of lists

Post by two_bits »

Lo everyone, is it possible to have a list of lists?
Or create a structure that contains a list?

something like:

structure JinglBells
newlist BatMansmells ()
endstructure
Rob
User
User
Posts: 26
Joined: Wed Jun 25, 2003 6:54 pm
Location: Lübeck - Germany
Contact:

Post by Rob »

<!-- /* ; // nop */ -->
two_bits
User
User
Posts: 15
Joined: Sat Oct 04, 2003 6:52 pm

Post by two_bits »

OK - thanx mate - i think i can just about understand how its done with the help of Babelfish :)
newbie
Enthusiast
Enthusiast
Posts: 296
Joined: Tue Jul 29, 2003 5:47 pm
Location: FRANCE
Contact:

Post by newbie »

Personally i use a linked list of a structure type :

Code: Select all

Structure keys
    keyvalue.b
    keypos.b
EndStructure

NewList SetKeys.keys()
then later in teh code i assign values :

Code: Select all

AddElement(SetKeys())
SetKeys()\keyvalue = 32 
SetKeys()\keypos = 1

AddElement(SetKeys())
SetKeys()\keyvalue = 54 
SetKeys()\keypos = 2
.
.
.
and at the end i use the values :

Code: Select all

ResetList(SetKeys())
While NextElement(SetKeys())
  keyval = SetKeys()\keyvalue
  pos = SetKeys()\keypos
.
.
.

linked lists are very usefull to store information with the exact memory size needed to store them, no need anymore of "Dim array.b(256)".

If you need more fields just add variables to your structure :)
- Registered PB user -

Using PB 4.00
Christian
Enthusiast
Enthusiast
Posts: 154
Joined: Mon Dec 08, 2003 7:50 pm
Location: Germany

Post by Christian »

Hi!

I found this in the CodeArchiv of Andre:

Code: Select all

; German forum: http://robsite.de/php/pureboard/viewtopic.php?t=1676&highlight=
; Author: NicTheQuick
; Date: 15. July 2003


; Example for using LinkedLists in LinkedLists
; Beispiel zur Verwendung von LinkedLists in LinkedLists

;Hier werden die Speicheradressen der einzelnen LinkedLists gespeichert 
NewList Speicher.l() 
;Hier sind die einzelnen LinkedLists gespeichert 
NewList LinkedList.l() 

Procedure NewLinkedList()           ;Erstellt eine neue LinkedList und ein neues Element in der Liste 
  If LastElement(LinkedList()) 
    AddressLast.l = @LinkedList() 
  EndIf 
  
  AddElement(LinkedList()) 
  Address.l = @LinkedList() 
  PokeL(Address - 8, 0) 
  PokeL(Address - 4, 0) 
  
  If AddressLast 
    PokeL(AddressLast - 8, 0) 
  EndIf 
  AddElement(Speicher()) 
  Speicher() = Address 
EndProcedure 

Procedure NextLinkedList()          ;Springt zur nächsten dynamischen LinkedList 
  If NextElement(Speicher()) 
    ChangeCurrentElement(LinkedList(), Speicher()) 
    ProcedureReturn #TRUE 
  Else 
    ProcedureReturn #FALSE 
  EndIf 
EndProcedure 

Procedure PreviousLinkedList()      ;Springt zur vorherigen dynamischen LinkedList 
  If PreviousElement(Speicher()) 
    ChangeCurrentElement(LinkedList(), Speicher()) 
    ProcedureReturn #TRUE 
  Else 
    ProcedureReturn #FALSE 
  EndIf 
EndProcedure 

Procedure FirstLinkedList()         ;Springt zur ersten LinkedList 
  If FirstElement(Speicher()) 
    ChangeCurrentElement(LinkedList(), Speicher()) 
  Else 
    ProcedureReturn #FALSE 
  EndIf 
EndProcedure 

Procedure LastLinkedList()          ;Springt zur letzten LinkedList 
  If LastElement(Speicher()) 
    ChangeCurrentElement(LinkedList(), Speicher()) 
  Else 
    ProcedureReturn #FALSE 
  EndIf 
EndProcedure 

Procedure DeleteLinkedList()        ;Löscht eine LinkedList mit allen Elementen 
  If @Speicher() 
    ChangeCurrentElement(LinkedList(), Speicher()) 
    DeleteElement(LinkedList()) 
    While NextElement(LinkedList()) 
      DeleteElement(LinkedList()) 
    Wend 
    DeleteElement(Speicher()) 
    ProcedureReturn #TRUE 
  Else 
    ProcedureReturn #FALSE 
  EndIf 
EndProcedure 

Procedure FirstLinkedListElement()  ;Springt zum ersten Element in der LinkedList 
  If Speicher() 
    ChangeCurrentElement(LinkedList(), Speicher()) 
  EndIf 
EndProcedure 

;BEISPIEL-CODE 
;¯¯¯¯¯¯¯¯¯¯¯¯¯ 
NewLinkedList()             ;Wir erstellen eine LinkedList mit 2 Elementen 
LinkedList() = 1 
AddElement(LinkedList()) 
LinkedList() = 2 

NewLinkedList()             ;Und noch eine mit 3 Elementen 
LinkedList() = 3 
AddElement(LinkedList()) 
LinkedList() = 4 
AddElement(LinkedList()) 
LinkedList() = 5 

NewLinkedList()             ;Noch eine mit 4 Elementen 
LinkedList() = 6 
AddElement(LinkedList()) 
LinkedList() = 7 
AddElement(LinkedList()) 
LinkedList() = 8 
AddElement(LinkedList()) 
LinkedList() = 9 

FirstLinkedList()           ;Wir springen zur ersten LinkedList 
Debug LinkedList() 
While NextElement(LinkedList()) 
  Debug LinkedList()        ;und gehen alle Elemente durch 
Wend 

LastLinkedList()            ;Die letzte LinkedList 
Debug LinkedList() 
While NextElement(LinkedList()) 
  Debug LinkedList() 
Wend 

PreviousLinkedList()        ;Die vorherige LinkedList 
Debug LinkedList() 
While NextElement(LinkedList()) 
  Debug LinkedList() 
Wend
regards,
Christian
Post Reply