September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -0,0 +1,87 @@
|
|||
* Singly-linked list/Element definition 07/02/2017
|
||||
LISTSINA CSECT
|
||||
USING LISTSINA,R13 base register
|
||||
B 72(R15) skip savearea
|
||||
DC 17F'0' savearea
|
||||
STM R14,R12,12(R13) prolog
|
||||
ST R13,4(R15) " <-
|
||||
ST R15,8(R13) " ->
|
||||
LR R13,R15 " addressability
|
||||
* Allocate A
|
||||
GETMAIN RU,LV=12 get storage
|
||||
USING NODE,R11 make storage addressable
|
||||
LR R11,R1 "
|
||||
MVC VAL,=CL8'A' val='A'
|
||||
MVC NEXT,=A(0)
|
||||
DROP R11 base no longer needed
|
||||
ST R11,A A=@A
|
||||
* Init LIST
|
||||
ST R11,LIST init LIST with A
|
||||
* Allocate C
|
||||
GETMAIN RU,LV=12 get storage
|
||||
USING NODE,R11 make storage addressable
|
||||
LR R11,R1 "
|
||||
MVC VAL,=CL8'C' val='C'
|
||||
MVC NEXT,=A(0)
|
||||
DROP R11 base no longer needed
|
||||
ST R11,C C=@C
|
||||
* Insert C After A
|
||||
MVC P1,A
|
||||
MVC P2,C
|
||||
LA R1,PARML
|
||||
BAL R14,INSERTAF
|
||||
* Allocate B
|
||||
GETMAIN RU,LV=12 get storage
|
||||
USING NODE,R11 make storage addressable
|
||||
LR R11,R1 "
|
||||
MVC VAL,=CL8'B' val='B'
|
||||
MVC NEXT,=A(0)
|
||||
DROP R11 base no longer needed
|
||||
ST R11,B B=@B
|
||||
* Insert B After A
|
||||
MVC P1,A
|
||||
MVC P2,B
|
||||
LA R1,PARML
|
||||
BAL R14,INSERTAF
|
||||
* List all
|
||||
L R11,LIST
|
||||
USING NODE,R11 address node
|
||||
LOOP C R11,=A(0)
|
||||
BE ENDLIST
|
||||
XPRNT VAL,8
|
||||
L R11,NEXT
|
||||
B LOOP
|
||||
ENDLIST DROP R11
|
||||
FREEMAIN A=A,LV=12 free A
|
||||
FREEMAIN A=B,LV=12 free B
|
||||
FREEMAIN A=C,LV=12 free C
|
||||
RETURN L R13,4(0,R13) epilog
|
||||
LM R14,R12,12(R13) " restore
|
||||
XR R15,R15 " rc=0
|
||||
BR R14 exit
|
||||
LIST DS A list head
|
||||
A DS A
|
||||
B DS A
|
||||
C DS A
|
||||
PARML DS 0A
|
||||
P1 DS A
|
||||
P2 DS A
|
||||
INSERTAF CNOP 0,4
|
||||
L R2,0(R1) @A
|
||||
L R3,4(R1) @B
|
||||
USING NODE,R2 ->A
|
||||
L R4,NEXT @C
|
||||
DROP R2
|
||||
USING NODE,R3 ->B
|
||||
ST R4,NEXT B.NEXT=@C
|
||||
DROP R3
|
||||
USING NODE,R2 ->A
|
||||
ST R3,NEXT A.NEXT=@B
|
||||
DROP R2
|
||||
BR R14 return
|
||||
LTORG all literals
|
||||
NODE DSECT node (size=12)
|
||||
VAL DS CL8
|
||||
NEXT DS A
|
||||
YREGS
|
||||
END LISTSINA
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
type Node{T}
|
||||
data::T
|
||||
next::Node{T}
|
||||
next::Nullable{Node{T}}
|
||||
|
||||
function Node(data::T)
|
||||
n = new()
|
||||
n.data = data
|
||||
# mark the end of the list. Julia does not have nil or null.
|
||||
n.next = n
|
||||
# To mark the end of the list we use the Nullable{T}() function .
|
||||
n.next = Nullable{Node{T}}()
|
||||
n
|
||||
end
|
||||
end
|
||||
|
|
@ -16,7 +16,7 @@ function Node(data)
|
|||
return Node{typeof(data)}(data)
|
||||
end
|
||||
|
||||
islast(n::Node) = (n == n.next)
|
||||
islast(n::Node) = (isnull(n.next))
|
||||
|
||||
function append{T}(n::Node{T}, data::T)
|
||||
tmp = Node(data)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
// version 1.1.2
|
||||
|
||||
class Node<T: Number>(var data: T, var next: Node<T>? = null) {
|
||||
override fun toString(): String {
|
||||
val sb = StringBuilder(this.data.toString())
|
||||
var node = this.next
|
||||
while (node != null) {
|
||||
sb.append(" -> ", node.data.toString())
|
||||
node = node.next
|
||||
}
|
||||
return sb.toString()
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val n = Node(1, Node(2, Node(3)))
|
||||
println(n)
|
||||
}
|
||||
|
|
@ -0,0 +1,133 @@
|
|||
list = .linkedlist~new
|
||||
index = list~insert("abc") -- insert a first item, keeping the index
|
||||
list~insert("def") -- adds to the end
|
||||
list~insert("123", .nil) -- adds to the begining
|
||||
list~insert("456", index) -- inserts between "abc" and "def"
|
||||
list~remove(index) -- removes "abc"
|
||||
|
||||
say "Manual list traversal"
|
||||
index = list~first -- demonstrate traversal
|
||||
loop while index \== .nil
|
||||
say index~value
|
||||
index = index~next
|
||||
end
|
||||
|
||||
say
|
||||
say "Do ... Over traversal"
|
||||
do value over list
|
||||
say value
|
||||
end
|
||||
|
||||
-- the main list item, holding the anchor to the links.
|
||||
::class linkedlist
|
||||
::method init
|
||||
expose anchor
|
||||
|
||||
-- create this as an empty list
|
||||
anchor = .nil
|
||||
|
||||
-- return first link element
|
||||
::method first
|
||||
expose anchor
|
||||
return anchor
|
||||
|
||||
-- return last link element
|
||||
::method last
|
||||
expose anchor
|
||||
|
||||
current = anchor
|
||||
loop while current \= .nil
|
||||
-- found the last one
|
||||
if current~next == .nil then return current
|
||||
current = current~next
|
||||
end
|
||||
-- empty
|
||||
return .nil
|
||||
|
||||
-- insert a value into the list, using the convention
|
||||
-- followed by the built-in list class. If the index item
|
||||
-- is omitted, add to the end. If the index item is .nil,
|
||||
-- add to the end. Otherwise, just chain to the provided link.
|
||||
::method insert
|
||||
expose anchor
|
||||
use arg value
|
||||
|
||||
newLink = .link~new(value)
|
||||
-- adding to the end
|
||||
if arg() == 1 then do
|
||||
if anchor == .nil then anchor = newLink
|
||||
else self~last~insert(newLink)
|
||||
end
|
||||
else do
|
||||
use arg ,index
|
||||
if index == .nil then do
|
||||
if anchor \== .nil then newLink~next = anchor
|
||||
anchor = newLink
|
||||
end
|
||||
else index~insert(newLink)
|
||||
end
|
||||
-- the link item serves as an "index"
|
||||
return newLink
|
||||
|
||||
-- remove a link from the chain
|
||||
::method remove
|
||||
expose anchor
|
||||
|
||||
use strict arg index
|
||||
|
||||
-- handle the edge case
|
||||
if index == anchor then anchor = anchor~next
|
||||
else do
|
||||
-- no back link, so we need to scan
|
||||
previous = self~findPrevious(index)
|
||||
-- invalid index, don't return any item
|
||||
if previous == .nil then return .nil
|
||||
previous~next = index~next
|
||||
end
|
||||
-- belt-and-braces, remove the link and return the value
|
||||
index~next = .nil
|
||||
return index~value
|
||||
|
||||
-- private method to find a link predecessor
|
||||
::method findPrevious private
|
||||
expose anchor
|
||||
use strict arg index
|
||||
|
||||
-- we're our own precessor if this first
|
||||
if index == anchor then return self
|
||||
|
||||
current = anchor
|
||||
loop while current \== .nil
|
||||
if current~next == index then return current
|
||||
current = current~next
|
||||
end
|
||||
-- not found
|
||||
return .nil
|
||||
|
||||
-- helper method to allow DO ... OVER traversal
|
||||
::method makearray
|
||||
expose anchor
|
||||
array = .array~new
|
||||
|
||||
current = anchor
|
||||
loop while current \= .nil
|
||||
array~append(current~value)
|
||||
current = current~next
|
||||
end
|
||||
return array
|
||||
|
||||
::class link
|
||||
::method init
|
||||
expose value next
|
||||
-- by default, initialize both data and next to empty.
|
||||
use strict arg value = .nil, next = .nil
|
||||
|
||||
-- allow external access to value and next link
|
||||
::attribute value
|
||||
::attribute next
|
||||
|
||||
::method insert
|
||||
expose next
|
||||
use strict arg newNode
|
||||
newNode~next = next
|
||||
next = newNode
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
enum NEXT,DATA
|
||||
type slnode(object x)
|
||||
return (sequence(x) and length(x)=DATA and myotherudt(x[DATA]) and integer(x[NEXT])
|
||||
end type
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
class Node<T>{
|
||||
var data:T?=nil
|
||||
var next:Node?=nil
|
||||
init(input:T){
|
||||
data=input
|
||||
next=nil
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,13 @@
|
|||
struct link
|
||||
.next: resd 1
|
||||
.data: resd 1
|
||||
; x86_64 Linux NASM
|
||||
; Linked_List_Definition.asm
|
||||
|
||||
%ifndef LinkedListDefinition
|
||||
%define LinkedListDefinition
|
||||
|
||||
struc link
|
||||
value: resd 1
|
||||
next: resq 1
|
||||
linkSize:
|
||||
endstruc
|
||||
|
||||
%endif
|
||||
|
|
|
|||
|
|
@ -1 +1,4 @@
|
|||
link resb 16
|
||||
struct link
|
||||
.next: resd 1
|
||||
.data: resd 1
|
||||
endstruc
|
||||
|
|
|
|||
|
|
@ -1,4 +1 @@
|
|||
link struct
|
||||
next dd ?
|
||||
data dd ?
|
||||
link ends
|
||||
link resb 16
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
struc link next,data
|
||||
{
|
||||
.next dd next
|
||||
.data dd data
|
||||
}
|
||||
link struct
|
||||
next dd ?
|
||||
data dd ?
|
||||
link ends
|
||||
|
|
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
struc link next,data
|
||||
{
|
||||
.next dd next
|
||||
.data dd data
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
List(1,"two",3.14); L(1,"two",3.14);
|
||||
ROList(fcn{"foobar"}); T('+);
|
||||
Loading…
Add table
Add a link
Reference in a new issue