RosettaCodeData/Task/Singly-linked-list-Traversal/PL-I/singly-linked-list-traversal.pli
2023-07-01 13:44:08 -04:00

41 lines
898 B
Text

*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;