Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,5 @@
|
|||
Lbl INSERT
|
||||
{r₁+2}ʳ→{r₂+2}ʳ
|
||||
r₂→{r₁+2}ʳ
|
||||
r₁
|
||||
Return
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
(define (insert-after lst target item)
|
||||
(when (null? lst) (error "cannot insert in" null))
|
||||
(let [(sub-list (member target lst))]
|
||||
(if sub-list (set-cdr! sub-list (cons item (cdr sub-list))) ; make chirurgy if found
|
||||
(nconc lst item)))) ; else append item
|
||||
|
||||
(define L '(a b))
|
||||
(insert-after L 'a 'c)
|
||||
L → (a c b)
|
||||
(insert-after L 'x 'y)
|
||||
L → (a c b y)
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
type Node[T] = ref object
|
||||
next: Node[T]
|
||||
data: T
|
||||
|
||||
proc newNode[T](data: T): Node[T] =
|
||||
Node[T](data: data)
|
||||
|
||||
var a = newNode 12
|
||||
var b = newNode 13
|
||||
var c = newNode 14
|
||||
|
||||
proc insertAppend(a, n: var Node) =
|
||||
n.next = a.next
|
||||
a.next = n
|
||||
|
||||
a.insertAppend(b)
|
||||
b.insertAppend(c)
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
Collection Class new: LinkedList(data, mutable next)
|
||||
|
||||
LinkedList method: initialize := next := data ;
|
||||
LinkedList method: data @data ;
|
||||
LinkedList method: next @next ;
|
||||
LinkedList method: add(e) e @next LinkedList new := next ;
|
||||
|
||||
LinkedList method: forEachNext
|
||||
dup ifNull: [ drop self ]
|
||||
dup 1 ifEq: [ drop false return ]
|
||||
dup next dup ifNull: [ drop 1 ]
|
||||
swap data true ;
|
||||
|
||||
: testLink LinkedList new($A, null) dup add($B) dup add($C) ;
|
||||
|
||||
testLink println
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
func insert_after(a,b) {
|
||||
b{:next} = a{:next};
|
||||
a{:next} = b;
|
||||
}
|
||||
|
||||
var B = Hash.new(
|
||||
data => 3,
|
||||
next => nil, # not a circular list
|
||||
);
|
||||
var A = Hash.new(
|
||||
data => 1,
|
||||
next => B,
|
||||
);
|
||||
var C = Hash.new(
|
||||
data => 2,
|
||||
);
|
||||
|
||||
insert_after(A, C);
|
||||
Loading…
Add table
Add a link
Reference in a new issue