Another update from ingydotnet^djgoku
This commit is contained in:
parent
91df62d461
commit
948b86eafa
7604 changed files with 108452 additions and 22726 deletions
|
|
@ -0,0 +1,14 @@
|
|||
% inserts a new value after the specified element of a list %
|
||||
procedure insert( reference(ListI) value list
|
||||
; integer value newValue
|
||||
) ;
|
||||
next(list) := ListI( newValue, next(list) );
|
||||
|
||||
% 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 ) ) ) );
|
||||
|
||||
% insert a new value into the list %
|
||||
insert( next(head), 4077 );
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
MODULE SinglyLinkedList EXPORTS Main;
|
||||
|
||||
TYPE
|
||||
Link = REF LinkRcd;
|
||||
LinkRcd = RECORD
|
||||
Next: Link;
|
||||
Data: INTEGER
|
||||
END;
|
||||
|
||||
PROCEDURE InsertAppend(anchor, next: Link) =
|
||||
BEGIN
|
||||
IF anchor # NIL AND next # NIL THEN
|
||||
next.Next := anchor.Next;
|
||||
anchor.Next := next
|
||||
END
|
||||
END InsertAppend;
|
||||
|
||||
VAR
|
||||
a: Link := NEW(Link, Next := NIL, Data := 1);
|
||||
b: Link := NEW(Link, Next := NIL, Data := 2);
|
||||
c: Link := NEW(Link, Next := NIL, Data := 3);
|
||||
|
||||
BEGIN
|
||||
InsertAppend(a, b);
|
||||
InsertAppend(a, c)
|
||||
END SinglyLinkedList.
|
||||
Loading…
Add table
Add a link
Reference in a new issue