September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -0,0 +1 @@
link=(prev=) (next=) (data=)

View file

@ -0,0 +1,24 @@
// version 1.1.2
class Node<T: Number>(var data: T, var prev: Node<T>? = null, 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 n1 = Node(1)
val n2 = Node(2, n1)
n1.next = n2
val n3 = Node(3, n2)
n2.next = n3
println(n1)
println(n2)
println(n3)
}

View file

@ -0,0 +1,19 @@
MODULE Box;
TYPE
Object* = POINTER TO ObjectDesc;
ObjectDesc* = (* ABSTRACT *) RECORD
END;
(* ... *)
END Box.
MODULE Collections;
TYPE
Node* = POINTER TO NodeDesc;
NodeDesc* = (* ABSTRACT *) RECORD
prev-,next-: Node;
value-: Box.Object;
END;
(* ... *)
END Collections.

View file

@ -0,0 +1,4 @@
enum NEXT,PREV,DATA
type slnode(object x)
return (sequence(x) and length(x)=DATA and <i>udt</i>(x[DATA]) and integer(x[NEXT] and integer(x[PREV]))
end type

View file

@ -1,17 +1,12 @@
pub struct LinkedList<T> { // User-facing implementation
length: usize,
list_head: Link<T>,
list_tail: Rawlink<Node<T>>,
}
type Link<T> = Option<Box<Node<T>>>; // Type definition
struct Rawlink<T> { // Pointer is wrapped in struct so that Option-like methods can be added to it later (wrappers around NULL checks)
p: *mut T, // Raw mutable pointer
pub struct LinkedList<T> {
head: Option<Shared<Node<T>>>,
tail: Option<Shared<Node<T>>>,
len: usize,
marker: PhantomData<Box<Node<T>>>, // Indicates that we logically own a boxed (owned pointer) Node<T>>
}
struct Node<T> {
next: Link<T>,
prev: Rawlink<Node<T>>,
value: T,
next: Option<Shared<Node<T>>>,
prev: Option<Shared<Node<T>>>,
element: T,
}

View file

@ -0,0 +1,5 @@
class Node{
fcn init(_value,_prev=Void,_next=Void)
{ var value=_value, prev=_prev, next=_next; }
fcn toString{ value.toString() }
}

View file

@ -0,0 +1,3 @@
a,b:=Node(1),Node("three");
a.next=b; b.prev=a;
println(a.next," ",b.prev);