Sync
This commit is contained in:
parent
6f050a029e
commit
776bba907c
3887 changed files with 59894 additions and 7280 deletions
|
|
@ -1 +1,3 @@
|
|||
Traverse from the beginning of a singly-linked list to the end.
|
||||
|
||||
{{Template:See also lists}}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
:- object(singly_linked_list).
|
||||
|
||||
:- public(show/0).
|
||||
|
||||
show :-
|
||||
traverse([1,2,3]).
|
||||
|
||||
traverse([]).
|
||||
traverse([Head| Tail]) :-
|
||||
write(Head), nl,
|
||||
traverse(Tail).
|
||||
|
||||
:- end_object.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
| ?- singly_linked_list::show.
|
||||
1
|
||||
2
|
||||
3
|
||||
yes
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
*process source attributes xref or(!);
|
||||
/*********************************************************************
|
||||
* 25.10.2013 Walter Pachl
|
||||
* 'set dd:in=d:\sll.txt,recsize(80)'
|
||||
* 'sll'
|
||||
*********************************************************************/
|
||||
sll: Proc Options(main);
|
||||
Dcl in Record Input;
|
||||
Dcl sysprint Print;
|
||||
Dcl 1 elem Based(p),
|
||||
2 next Ptr Init(null()),
|
||||
2 value Char(20) Var;
|
||||
Dcl head Ptr;
|
||||
Dcl p Ptr;
|
||||
Dcl prev Ptr;
|
||||
Dcl i Bin Fixed(31);
|
||||
Dcl rec Char(80) Var;
|
||||
Dcl null Builtin;
|
||||
On Endfile(in) goto show;
|
||||
Do i=1 By 1;
|
||||
Read File(in) Into(rec);
|
||||
alloc elem set(p);
|
||||
If i=1 Then Do;
|
||||
head=p;
|
||||
prev=head;
|
||||
value=rec;
|
||||
End;
|
||||
Else Do;
|
||||
prev->next=p;
|
||||
prev=p;
|
||||
value=rec;
|
||||
End;
|
||||
End;
|
||||
|
||||
show:
|
||||
p=head;
|
||||
Do i=1 By 1 while(p^=null());
|
||||
Put Edit(i,p->value)(skip,f(3),x(1),a);
|
||||
p=p->next;
|
||||
End;
|
||||
End;
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
/*********************************************************************
|
||||
* 25.10.2013 Walter Pachl
|
||||
*********************************************************************/
|
||||
in='d:\sll.txt'
|
||||
Do i=1 By 1 while lines(in)>0
|
||||
rec=linein(in)
|
||||
elem.i.val=rec
|
||||
elem.i.next=0
|
||||
ip=i-1
|
||||
elem.ip.next=i
|
||||
End;
|
||||
c=1
|
||||
Do While c<>0
|
||||
Say c elem.c.val
|
||||
c=elem.c.next
|
||||
End
|
||||
Loading…
Add table
Add a link
Reference in a new issue