RosettaCodeData/Task/Doubly-linked-list-Definition/FutureBasic/doubly-linked-list-definiti...

68 lines
1.2 KiB
Plaintext

begin globals
str255 List(8) //create a new list of strings (List(0) not used
end globals
local fn ShowList(title As str255)
//display all elements from list of string
short j
Print title;
For j = 1 to 7
Print List(j); " ";
Next j
Print ""
End fn
/////////// MAIN PROGRAM ////////////
Dim As str255 item //items to add to the list
Dim As short i,j, c = 0
//the list of data that will be added to the list
data:
Data "One", "Two", "Three", "Four", "Five", "Six", "EndOfData"
Restore
c = 0
Do
Read item
If item <> "EndOfData" Then List(c) = item
c ++
Until item = "EndOfData"
str255 ListTMP(7)
For j = 1 To 7
ListTMP(7-j) = List(j)
Next j
For j = 1 To 7
Swap List(j), ListTMP(j)
Next j
fn ShowList("Insertion at Head: ")
for i = 1 to 7 : List(i) = "" : next i // clear list
Restore
c = 0
Do
Read item //: c += 1
If item <> "EndOfData" Then List(c) = item
c ++
Until item = "EndOfData"
fn ShowList("Insertion at Tail: ")
for i = 1 to 7 : List(i) = "" : next i // clear list
Restore
c = 0
Do
Read item //: c += 1
If item <> "EndOfData" Then List(c) = item
c ++
Until item = "EndOfData"
Swap List(3), List(6)
fn ShowList("Insertion in Middle: ")
handleevents