Traverse from the beginning of a singly-linked list to the end.



See also

 Array
 Associative array: Creation, Iteration
 Collections
 Compound data type
 Doubly-linked list: Definition, Element definition, Element insertion, List Traversal, Element Removal
 Linked list
 Queue: Definition, Usage
 Set
 Singly-linked list: Element definition, Element insertion, List Traversal, Element Removal
 Stack


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