Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,3 @@
---
from: http://rosettacode.org/wiki/Singly-linked_list/Element_definition
note: Data Structures

View file

@ -0,0 +1,4 @@
Define the data structure for a [[singly-linked list]] element. Said element should contain a data member capable of holding a numeric value, and the link to the next element should be mutable.
{{Template:See also lists}}

View file

@ -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

View file

@ -0,0 +1,16 @@
;create a node at address $0020, and another node at address $0040.
;The first node has a value of #$77, the second, #$99.
;create first node
LDA #$77
STA $20
LDA #$40
STA $21
LDA #$00
STA $22
;create second node
LDA #$99
STA $40
LDA #$FF ;use $FFFF as the null pointer since the only thing that can be at address $FFFF is the high byte of the IRQ routine.
STA $41
STA $42

View file

@ -0,0 +1,57 @@
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program defList.s */
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
.equ NBELEMENTS, 100 // list size
/*******************************************/
/* Structures */
/********************************************/
/* structure linkedlist*/
.struct 0
llist_next: // next element
.struct llist_next + 8
llist_value: // element value
.struct llist_value + 8
llist_fin:
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szMessInitListe: .asciz "List initialized.\n"
szCarriageReturn: .asciz "\n"
/* datas error display */
szMessErreur: .asciz "Error detected.\n"
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
lList1: .skip llist_fin * NBELEMENTS // list memory place
/*******************************************/
/* code section */
/*******************************************/
.text
.global main
main:
ldr x0,qAdrlList1
mov x1,#0
str x1,[x0,#llist_next]
ldr x0,qAdrszMessInitListe
bl affichageMess
100: // standard end of the program
mov x8, #EXIT // request to exit program
svc 0 // perform system call
qAdrszMessInitListe: .quad szMessInitListe
qAdrszMessErreur: .quad szMessErreur
qAdrszCarriageReturn: .quad szCarriageReturn
qAdrlList1: .quad lList1
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"

View file

@ -0,0 +1,3 @@
(let ((elem 8)
(next (list 6 7 5 3 0 9)))
(cons elem next))

View file

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*- #
CO REQUIRES:
MODE OBJVALUE = ~ # Mode/type of actual obj to be stacked #
END CO
MODE OBJNEXTLINK = STRUCT(
REF OBJNEXTLINK next,
OBJVALUE value # ... etc. required #
);
PROC obj nextlink new = REF OBJNEXTLINK:
HEAP OBJNEXTLINK;
PROC obj nextlink free = (REF OBJNEXTLINK free)VOID:
next OF free := obj stack empty # give the garbage collector a BIG hint #

View file

@ -0,0 +1,8 @@
% record type to hold a singly linked list of integers %
record ListI ( integer iValue; reference(ListI) next );
% declare a variable to hold a list %
reference(ListI) head;
% create a list of integers %
head := ListI( 1701, ListI( 9000, ListI( 42, ListI( 90210, null ) ) ) );

View file

@ -0,0 +1,68 @@
/* ARM assembly Raspberry PI */
/* program defList.s */
/* Constantes */
.equ STDOUT, 1 @ Linux output console
.equ EXIT, 1 @ Linux syscall
.equ READ, 3
.equ WRITE, 4
.equ NBELEMENTS, 100 @ list size
/*******************************************/
/* Structures */
/********************************************/
/* structure linkedlist*/
.struct 0
llist_next: @ next element
.struct llist_next + 4
llist_value: @ element value
.struct llist_value + 4
llist_fin:
/* Initialized data */
.data
szMessInitListe: .asciz "List initialized.\n"
szCarriageReturn: .asciz "\n"
/* datas error display */
szMessErreur: .asciz "Error detected.\n"
/* UnInitialized data */
.bss
lList1: .skip llist_fin * NBELEMENTS @ list memory place
/* code section */
.text
.global main
main:
ldr r0,iAdrlList1
mov r1,#0
str r1,[r0,#llist_next]
ldr r0,iAdrszMessInitListe
bl affichageMess
100: @ standard end of the program
mov r7, #EXIT @ request to exit program
svc 0 @ perform system call
iAdrszMessInitListe: .int szMessInitListe
iAdrszMessErreur: .int szMessErreur
iAdrszCarriageReturn: .int szCarriageReturn
iAdrlList1: .int lList1
/******************************************************************/
/* display text with size calculation */
/******************************************************************/
/* r0 contains the address of the message */
affichageMess:
push {r0,r1,r2,r7,lr} @ save registers
mov r2,#0 @ counter length */
1: @ loop length calculation
ldrb r1,[r0,r2] @ read octet start position + index
cmp r1,#0 @ if 0 its over
addne r2,r2,#1 @ else add 1 in the length
bne 1b @ and loop
@ so here r2 contains the length of the message
mov r1,r0 @ address message in r1
mov r0,#STDOUT @ code to write to the standard output Linux
mov r7, #WRITE @ code call system "write"
svc #0 @ call system
pop {r0,r1,r2,r7,lr} @ restaur registers
bx lr @ return

View file

@ -0,0 +1,19 @@
(* The Rosetta Code linear list type can contain any vt@ype.
(The @ means it doesnt have to be the size of a pointer.
You can read {0 <= n} as for all non-negative n. *)
dataviewtype rclist_vt (vt : vt@ype+, n : int) =
| rclist_vt_nil (vt, 0)
| {0 <= n} rclist_vt_cons (vt, n + 1) of (vt, rclist_vt (vt, n))
(* A lemma one will need: lists never have negative lengths. *)
extern prfun {vt : vt@ype}
lemma_rclist_vt_param
{n : int}
(lst : !rclist_vt (vt, n)) :<prf> [0 <= n] void
(* Proof of the lemma. *)
primplement {vt}
lemma_rclist_vt_param lst =
case+ lst of
| rclist_vt_nil () => ()
| rclist_vt_cons _ => ()

View file

@ -0,0 +1,23 @@
BEGIN {
NIL = 0
HEAD = 1
LINK = 1
VALUE = 2
delete list
initList()
}
function initList() {
delete list
list[HEAD] = makeNode(NIL, NIL)
}
function makeNode(link, value) {
return link SUBSEP value
}
function getNode(part, nodePtr, linkAndValue) {
split(list[nodePtr], linkAndValue, SUBSEP)
return linkAndValue[part]
}

View file

@ -0,0 +1,5 @@
DEFINE PTR="CARD"
TYPE ListNode=[
BYTE data
PTR nxt]

View file

@ -0,0 +1,13 @@
package
{
public class Node
{
public var data:Object = null;
public var link:Node = null;
public function Node(obj:Object)
{
data = obj;
}
}
}

View file

@ -0,0 +1,6 @@
type Link;
type Link_Access is access Link;
type Link is record
Next : Link_Access := null;
Data : Integer;
end record;

View file

@ -0,0 +1,2 @@
element = 5 ; data
element_next = element2 ; link to next element

View file

@ -0,0 +1,13 @@
Lbl LINK
r₂→{r₁}ʳ
0→{r₁+2}ʳ
r₁
Return
Lbl NEXT
{r₁+2}ʳ
Return
Lbl VALUE
{r₁}ʳ
Return

View file

@ -0,0 +1 @@
DIM node{pNext%, iData%}

View file

@ -0,0 +1,6 @@
new$link:?link1
& new$link:?link2
& first thing:?(link1..data)
& secundus:?(link2..data)
& '$link2:(=?(link1..next))
& !(link1..next..data)

View file

@ -0,0 +1,5 @@
struct link
{
link* next;
int data;
};

View file

@ -0,0 +1,6 @@
struct link
{
link* next;
int data;
link(int a_data, link* a_next = 0): next(a_next), data(a_data) {}
};

View file

@ -0,0 +1 @@
link* small_primes = new link(2, new link(3, new link(5, new link(7))));

View file

@ -0,0 +1,6 @@
template<typename T> struct link
{
link* next;
T data;
link(T a_data, link* a_next = 0): next(a_next), data(a_data) {}
};

View file

@ -0,0 +1,12 @@
class LinkedListNode
{
public int Value { get; set; }
public LinkedListNode Next { get; set; }
// A constructor is not necessary, but could be useful.
public Link(int value, LinkedListNode next = null)
{
Item = value;
Next = next;
}
}

View file

@ -0,0 +1,11 @@
class LinkedListNode<T>
{
public T Value { get; set; }
public LinkedListNode Next { get; set; }
public Link(T value, LinkedListNode next = null)
{
Item = value;
Next = next;
}
}

View file

@ -0,0 +1,4 @@
unsafe struct link {
public link* next;
public int data;
};

View file

@ -0,0 +1,4 @@
struct link {
struct link *next;
int data;
};

View file

@ -0,0 +1,3 @@
import StdMaybe
:: Link t = { next :: Maybe (Link t), data :: t }

View file

@ -0,0 +1 @@
(cons 1 (cons 2 (cons 3 nil))) ; =>(1 2 3)

View file

@ -0,0 +1 @@
(cons 1 (cons 2 (cons 3 nil)) => (1 2 3)

View file

@ -0,0 +1,9 @@
struct SLinkedNode(T) {
T data;
typeof(this)* next;
}
void main() {
alias SLinkedNode!int N;
N* n = new N(10);
}

View file

@ -0,0 +1,6 @@
Type
pOneWayList = ^OneWayList;
OneWayList = record
pData : pointer ;
Next : pOneWayList ;
end;

View file

@ -0,0 +1,7 @@
use_namespace(rosettacode)_me();
add_struct(link)_arg({link},next,{int},data);
add_link(primeNumbers)_arg([],2)_link()_arg([],3)_link()_arg([],5)_link()_arg(null,7);
reset_namespace[];

View file

@ -0,0 +1,13 @@
interface LinkedList guards LinkedListStamp {}
def empty implements LinkedListStamp {
to null() { return true }
}
def makeLink(value :int, var next :LinkedList) {
def link implements LinkedListStamp {
to null() { return false }
to value() { return value }
to next() { return next }
to setNext(new) { next := new }
}
return link
}

View file

@ -0,0 +1,11 @@
class Link
{
prop int Item;
prop Link Next;
constructor(int item, Link next)
{
Item := item;
Next := next
}
}

View file

@ -0,0 +1 @@
new( Data ) -> erlang:spawn( fun() -> loop( Data, nonext ) end ).

View file

@ -0,0 +1,4 @@
TUPLE: linked-list data next ;
: <linked-list> ( data -- linked-list )
linked-list new swap >>data ;

View file

@ -0,0 +1,11 @@
class Node
{
const Int value // keep value fixed
Node? successor // allow successor to change, also, can be 'null', for end of list
new make (Int value, Node? successor := null)
{
this.value = value
this.successor = successor
}
}

View file

@ -0,0 +1,3 @@
0 value numbers
: push ( n -- )
here swap numbers , , to numbers ;

View file

@ -0,0 +1,8 @@
: length ( list -- u )
0 swap begin dup while 1 under+ @ repeat drop ;
: head ( list -- x )
cell+ @ ;
: .numbers ( list -- )
begin dup while dup head . @ repeat drop ;

View file

@ -0,0 +1,8 @@
type node
real :: data
type( node ), pointer :: next => null()
end type node
!
!. . . .
!
type( node ) :: head

View file

@ -0,0 +1,4 @@
type ll_int
n as integer
nxt as ll_int ptr
end type

View file

@ -0,0 +1,18 @@
type Ele struct {
Data interface{}
Next *Ele
}
func (e *Ele) Append(data interface{}) *Ele {
if e.Next == nil {
e.Next = &Ele{data, nil}
} else {
tmp := &Ele{data, e.Next}
e.Next = tmp
}
return e.Next
}
func (e *Ele) String() string {
return fmt.Sprintf("Ele: %v", e.Data)
}

View file

@ -0,0 +1,5 @@
class ListNode {
Object payload
ListNode next
String toString() { "${payload} -> ${next}" }
}

View file

@ -0,0 +1,4 @@
def n1 = new ListNode(payload:25)
n1.next = new ListNode(payload:88)
println n1

View file

@ -0,0 +1 @@
data List a = Nil | Cons a (List a)

View file

@ -0,0 +1 @@
data IntList s = Nil | Cons Integer (STRef s (IntList s))

View file

@ -0,0 +1 @@
record Node (value, successor)

View file

@ -0,0 +1,2 @@
list=: 0 2$0
list

View file

@ -0,0 +1,3 @@
list=: ,: _ 42
list
_ 42

View file

@ -0,0 +1,7 @@
list=: 0 2$a: NB. creates list with 0 items
list
list=: ,: (<_) , <'some text' NB. creates list with 1 item
list
+-+---------+
|_|some text|
+-+---------+

View file

@ -0,0 +1,5 @@
class Link
{
Link next;
int data;
}

View file

@ -0,0 +1,6 @@
class Link
{
Link next;
int data;
Link(int a_data, Link a_next) { next = a_next; data = a_data; }
}

View file

@ -0,0 +1 @@
Link small_primes = new Link(2, new Link(3, new Link(5, new Link(7, null))));

View file

@ -0,0 +1,6 @@
class Link<T>
{
Link<T> next;
T data;
Link(T a_data, Link<T> a_next) { next = a_next; data = a_data; }
}

View file

@ -0,0 +1,30 @@
function LinkedList(value, next) {
this._value = value;
this._next = next;
}
LinkedList.prototype.value = function() {
if (arguments.length == 1)
this._value = arguments[0];
else
return this._value;
}
LinkedList.prototype.next = function() {
if (arguments.length == 1)
this._next = arguments[0];
else
return this._next;
}
// convenience function to assist the creation of linked lists.
function createLinkedListFromArray(ary) {
var head = new LinkedList(ary[0], null);
var prev = head;
for (var i = 1; i < ary.length; i++) {
var node = new LinkedList(ary[i], null);
prev.next(node);
prev = node;
}
return head;
}
var head = createLinkedListFromArray([10,20,30,40]);

View file

@ -0,0 +1,24 @@
def is_empty_singly_linked_list:
type == "object" and .next == null and (has("item")|not);
def is_singly_linked_list:
is_empty_singly_linked_list or
(type == "object"
and has("item")
and (.next | ((. == null) or is_singly_linked_list)));
# Test for equality without checking for validity:
def equal_singly_linked_lists($x; $y):
($x|is_empty_singly_linked_list) as $xempty
| if $xempty then ($y|is_empty_singly_linked_list)
elif ($y|is_empty_singly_linked_list)
then $xempty
else ($x.item) == ($y.item)
and equal_singly_linked_lists($x.next; $y.next)
end;
# insert $x into the front of the SLL
def insert($x):
if is_empty_singly_linked_list then {item: $x, next: null}
else .next |= new($x; .)
end;

View file

@ -0,0 +1,59 @@
abstract type AbstractNode{T} end
struct EmptyNode{T} <: AbstractNode{T} end
mutable struct Node{T} <: AbstractNode{T}
data::T
next::AbstractNode{T}
end
Node{T}(x) where T = Node{T}(x::T, EmptyNode{T}())
mutable struct LinkedList{T}
head::AbstractNode{T}
end
LinkedList{T}() where T = LinkedList{T}(EmptyNode{T}())
LinkedList() = LinkedList{Any}()
Base.isempty(ll::LinkedList) = ll.head isa EmptyNode
function lastnode(ll::LinkedList)
if isempty(ll) throw(BoundsError()) end
nd = ll.head
while !(nd.next isa EmptyNode)
nd = nd.next
end
return nd
end
function Base.push!(ll::LinkedList{T}, x::T) where T
nd = Node{T}(x)
if isempty(ll)
ll.head = nd
else
tail = lastnode(ll)
tail.next = nd
end
return ll
end
function Base.pop!(ll::LinkedList{T}) where T
if isempty(ll)
throw(ArgumentError("list must be non-empty"))
elseif ll.head.next isa EmptyNode
nd = ll.head
ll.head = EmptyNode{T}()
else
nx = ll.head
while !isa(nx.next.next, EmptyNode)
nx = nx.next
end
nd = nx.next
nx.next = EmptyNode{T}()
end
return nd.data
end
lst = LinkedList{Int}()
push!(lst, 1)
push!(lst, 2)
push!(lst, 3)
pop!(lst) # 3
pop!(lst) # 2
pop!(lst) # 1

View file

@ -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)
}

View file

@ -0,0 +1,4 @@
&Node = {
$next
$data
}

View file

@ -0,0 +1,5 @@
fput item list ; add item to the head of a list
first list ; get the data
butfirst list ; get the remainder
bf list ; contraction for "butfirst"

View file

@ -0,0 +1,2 @@
.setfirst list value
.setbf list remainder

View file

@ -0,0 +1,6 @@
TYPE
Link = POINTER TO LinkRcd;
LinkRcd = RECORD
Next: Link;
Data: INTEGER
END;

View file

@ -0,0 +1,6 @@
TYPE
Link = REF LinkRcd;
LinkRcd = RECORD
Next: Link;
Data: INTEGER
END;

View file

@ -0,0 +1,4 @@
class link
declare data
declare next
end

View file

@ -0,0 +1,9 @@
class link
declare data
declare next
def link(data, next)
this.data = data
this.next = next
end
end

View file

@ -0,0 +1 @@
linkedlist = new(link, 1, new(link, 2, new(link, 3, new(link, 4, null))))

View file

@ -0,0 +1,47 @@
type
Node[T] = ref object
next: Node[T]
data: T
SinglyLinkedList[T] = object
head, tail: Node[T]
proc newNode[T](data: T): Node[T] =
Node[T](data: data)
proc append[T](list: var SinglyLinkedList[T]; node: Node[T]) =
if list.head.isNil:
list.head = node
list.tail = node
else:
list.tail.next = node
list.tail = node
proc append[T](list: var SinglyLinkedList[T]; data: T) =
list.append newNode(data)
proc prepend[T](list: var SinglyLinkedList[T]; node: Node[T]) =
if list.head.isNil:
list.head = node
list.tail = node
else:
node.next = list.head
list.head = node
proc prepend[T](list: var SinglyLinkedList[T]; data: T) =
list.prepend newNode(data)
proc `$`[T](list: SinglyLinkedList[T]): string =
var s: seq[T]
var n = list.head
while not n.isNil:
s.add n.data
n = n.next
result = s.join("")
var list: SinglyLinkedList[int]
for i in 1..5: list.append(i)
for i in 6..10: list.prepend(i)
echo "List: ", list

View file

@ -0,0 +1 @@
type 'a list = Nil | Cons of 'a * 'a list

View file

@ -0,0 +1 @@
type int_list = Nil | Cons of int * int_list ref

View file

@ -0,0 +1,33 @@
#import <Foundation/Foundation.h>
@interface RCListElement<T> : NSObject
{
RCListElement<T> *next;
T datum;
}
- (RCListElement<T> *)next;
- (T)datum;
- (RCListElement<T> *)setNext: (RCListElement<T> *)nx;
- (void)setDatum: (T)d;
@end
@implementation RCListElement
- (RCListElement *)next
{
return next;
}
- (id)datum
{
return datum;
}
- (RCListElement *)setNext: (RCListElement *)nx
{
RCListElement *p = next;
next = nx;
return p;
}
- (void)setDatum: (id)d
{
datum = d;
}
@end

View file

@ -0,0 +1,4 @@
Node :: struct {
data: rune,
next: ^Node,
}

View file

@ -0,0 +1 @@
Collection Class new: LinkedList(data, mutable next)

View file

@ -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

View file

@ -0,0 +1,3 @@
declare 1 node based (p),
2 value fixed,
2 link pointer;

View file

@ -0,0 +1,6 @@
type
PLink = ^TLink;
TLink = record
FNext: PLink;
FData: integer;
end;

View file

@ -0,0 +1,5 @@
my %node = (
data => 'say what',
next => \%foo_node,
);
$node{next} = \%bar_node; # mutable

View file

@ -0,0 +1,6 @@
(phixonline)-->
<span style="color: #008080;">enum</span> <span style="color: #000000;">NEXT</span><span style="color: #0000FF;">,</span><span style="color: #000000;">DATA</span>
<span style="color: #008080;">type</span> <span style="color: #000000;">slnode</span><span style="color: #0000FF;">(</span><span style="color: #004080;">object</span> <span style="color: #000000;">x</span><span style="color: #0000FF;">)</span>
<span style="color: #008080;">return</span> <span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">and</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">)=</span><span style="color: #000000;">DATA</span> <span style="color: #008080;">and</span> <span style="color: #000000;">myotherudt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">[</span><span style="color: #000000;">DATA</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">and</span> <span style="color: #004080;">integer</span><span style="color: #0000FF;">(</span><span style="color: #000000;">x</span><span style="color: #0000FF;">[</span><span style="color: #000000;">NEXT</span><span style="color: #0000FF;">])</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">type</span>
<!--

View file

@ -0,0 +1,15 @@
;;; Use shorthand syntax to create list.
lvars l1 = [1 2 three 'four'];
;;; Allocate a single list node, with value field 1 and the link field
;;; pointing to empty list
lvars l2 = cons(1, []);
;;; print first element of l1
front(l1) =>
;;; print the rest of l1
back(l1) =>
;;; Use index notation to access third element
l1(3) =>
;;; modify link field of l2 to point to l1
l1 -> back(l2);
;;; Print l2
l2 =>

View file

@ -0,0 +1,16 @@
uses objectclass;
define :class ListNode;
slot value = [];
slot next = [];
enddefine;
;;; Allocate new node and assign to l1
newListNode() -> l1;
;;; Print it
l1 =>
;;; modify value
1 -> value(l1);
l1 =>
;;; Allocate new node with initialized values and assign to link field
;;; of l1
consListNode(2, []) -> next(l1);
l1 =>

View file

@ -0,0 +1,4 @@
Structure MyData
*next.MyData
Value.i
EndStructure

View file

@ -0,0 +1,27 @@
class LinkedList(object):
"""USELESS academic/classroom example of a linked list implemented in Python.
Don't ever consider using something this crude! Use the built-in list() type!
"""
class Node(object):
def __init__(self, item):
self.value = item
self.next = None
def __init__(self, item=None):
if item is not None:
self.head = Node(item); self.tail = self.head
else:
self.head = None; self.tail = None
def append(self, item):
if not self.head:
self.head = Node(item)
self.tail = self.head
elif self.tail:
self.tail.next = Node(item)
self.tail = self.tail.next
else:
self.tail = Node(item)
def __iter__(self):
cursor = self.head
while cursor:
yield cursor.value
cursor = cursor.next

View file

@ -0,0 +1,38 @@
/*REXX program demonstrates how to create and show a single-linked list.*/
@.=0 /*define a null linked list. */
call set@ 3 /*linked list: 12 Proth Primes. */
call set@ 5
call set@ 13
call set@ 17
call set@ 41
call set@ 97
call set@ 113
call set@ 193
call set@ 241
call set@ 257
call set@ 353
call set@ 449
w=@.max_width /*use the maximum width of nums. */
call list@ /*list all the elements in list. */
exit /*stick a fork in it, we're done.*/
/*──────────────────────────────────LIST@ subroutine────────────────────*/
list@: say; w=max(7, @.max_width ) /*use the max width of nums or 7.*/
say center('item',6) center('value',w) center('next',6)
say center('' ,6,'') center('' ,w,'') center('' ,6,'')
p=1
do j=1 until p==0 /*show all entries of linked list*/
say right(j,6) right(@.p._value,w) right(@.p._next,6)
p=@.p._next
end /*j*/
return
/*──────────────────────────────────SET@ subroutine─────────────────────*/
set@: procedure expose @.; parse arg y /*get element to be added to list*/
_=@._last /*set the previous last element. */
n=_+1 /*bump last ptr in linked list. */
@._._next=n /*set the next pointer value. */
@._last=n /*define next item in linked list*/
@.n._value=y /*set item to the value specified*/
@.n._next=0 /*set the next pointer value. */
@..y=n /*set a locator pointer to self. */
@.max_width=max(@.max_width,length(y)) /*set maximum width of any value.*/
return /*return to invoker of this sub. */

View file

@ -0,0 +1,2 @@
#lang racket
(mcons 1 (mcons 2 (mcons 3 '()))) ; a mutable list

View file

@ -0,0 +1 @@
my $elem = 42 => $nextelem;

View file

@ -0,0 +1,10 @@
class Cell {
has $.value is rw;
has Cell $.next is rw;
# ...convenience methods here...
}
sub cons ($value, $next) { Cell.new(:$value, :$next) }
my $list = cons 10, (cons 20, (cons 30, Nil));

View file

@ -0,0 +1,28 @@
class ListNode
attr_accessor :value, :succ
def initialize(value, succ=nil)
self.value = value
self.succ = succ
end
def each(&b)
yield self
succ.each(&b) if succ
end
include Enumerable
def self.from_array(ary)
head = self.new(ary[0], nil)
prev = head
ary[1..-1].each do |val|
node = self.new(val, nil)
prev.succ = node
prev = node
end
head
end
end
list = ListNode.from_array([1,2,3,4])

View file

@ -0,0 +1,3 @@
data = 10
link = 10
dim node{data,link}

View file

@ -0,0 +1,4 @@
struct Node<T> {
elem: T,
next: Option<Box<Node<T>>>,
}

View file

@ -0,0 +1,16 @@
type Link<T> = Option<Box<Node<T>>>; // Type alias
pub struct List<T> { // User-facing interface for list
head: Link<T>,
}
struct Node<T> { // Private implementation of Node
elem: T,
next: Link<T>,
}
impl<T> List<T> {
#[inline]
pub fn new() -> Self { // List constructor
List { head: None }
// Add other methods here
}

View file

@ -0,0 +1,8 @@
extern crate LinkedList; // Name is arbitrary here
use LinkedList::List;
fn main() {
let list = List::new();
// Do stuff
}

View file

@ -0,0 +1,6 @@
01000000000000000000000000000000 26. 2
01111000000000000000000000000000 27. 30
10000000000000000000000000000000 28. 1
01011000000000000000000000000000 29. 26
11000000000000000000000000000000 30. 3
00000000000000000000000000000000 31. 0

View file

@ -0,0 +1,8 @@
sealed trait List[+A]
case class Cons[+A](head: A, tail: List[A]) extends List[A]
case object Nil extends List[Nothing]
object List {
def apply[A](as: A*): List[A] =
if (as.isEmpty) Nil else Cons(as.head, apply(as.tail: _*))
}

View file

@ -0,0 +1,3 @@
def main(args: Array[String]): Unit = {
val words = List("Rosetta", "Code", "Scala", "Example")
}

View file

@ -0,0 +1,2 @@
(car my-list) ; returns the first element of the list
(cdr my-list) ; returns the remainder of the list

View file

@ -0,0 +1,2 @@
(set-car! my-list new-elem)
(set-cdr! my-list new-next)

View file

@ -0,0 +1,6 @@
var node = Hash.new(
data => 'say what',
next => foo_node,
);
node{:next} = bar_node; # mutable

View file

@ -0,0 +1,8 @@
struct item {
transmorphic scalar value
pointer(struct item scalar) scalar next
}
struct list {
pointer(struct item scalar) scalar head, tail
}

Some files were not shown because too many files have changed in this diff Show more