Doubly-linked list/Definition: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
(Doubly-linked list/Definition in FreeBASIC) |
||
Line 2,248: | Line 2,248: | ||
Doubly-linked list has 5 element - bwd = 7, 5, 4, 3, 1 |
Doubly-linked list has 5 element - bwd = 7, 5, 4, 3, 1 |
||
</pre> |
</pre> |
||
=={{header|FreeBASIC}}== |
|||
<syntaxhighlight lang="vb">Sub InsertaElto(lista() As String, posic As Integer = 1) |
|||
For i As Integer = Lbound(lista) To Ubound(lista) |
|||
If i = posic Then Swap lista(i), lista(Ubound(lista)) |
|||
Next i |
|||
End Sub |
|||
Sub mostrarLista(lista() As String, titulo As String) |
|||
'display all elements from list of strings |
|||
Print !"\n"; titulo; |
|||
For i As Integer = Lbound(lista) To Ubound(lista) |
|||
Print lista(i); " "; |
|||
Next i |
|||
Print "" |
|||
End Sub |
|||
Dim As String arr() 'create a new list of strings |
|||
Dim As String elto 'items to add to the list |
|||
Dim As Integer j, c = 0 |
|||
Restore datos |
|||
Do |
|||
Read elto : c += 1 |
|||
If elto <> "EndOfData" Then Redim Preserve arr(c) : arr(c) = elto |
|||
Loop Until elto = "EndOfData" |
|||
Dim As Integer lb = Lbound(arr), ub = Ubound(arr) |
|||
Dim As String arrTMP(ub) |
|||
For j = lb To ub : arrTMP(ub-j) = arr(j) |
|||
Next j |
|||
For j = lb To ub : Swap arr(j), arrTMP(j) |
|||
Next j |
|||
mostrarLista(arr(),"Insertion at Head: ") |
|||
Erase arr |
|||
Restore datos |
|||
c = 0 |
|||
Do |
|||
Read elto : c += 1 |
|||
If elto <> "EndOfData" Then Redim Preserve arr(c) : arr(c) = elto |
|||
Loop Until elto = "EndOfData" |
|||
mostrarLista(arr(),"Insertion at Tail:") |
|||
Erase arr |
|||
Restore datos |
|||
c = 0 |
|||
Do |
|||
Read elto : c += 1 |
|||
If elto <> "EndOfData" Then Redim Preserve arr(c) : arr(c) = elto |
|||
Loop Until elto = "EndOfData" |
|||
InsertaElto(arr(), 3) |
|||
mostrarLista(arr(),"Insertion in Middle:") |
|||
Sleep |
|||
'the list of datos that will be added to the list |
|||
datos: |
|||
Data "One", "Two", "Three", "Four", "Five", "Six", "EndOfData"</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Insertion at Head: Six Five Four Three Two One |
|||
Insertion at Tail: One Two Three Four Five Six |
|||
Insertion in Middle: One Two Six Four Five Three</pre> |
|||
=={{header|Go}}== |
=={{header|Go}}== |