program r4(input,output);
uses crt;
Type
        Tz2=char;
        sp2=^zv2;
        zv2=record
            elem:Tz2;
            before,next:sp2
            end;
        kolco=sp2;
var
        ring:kolco;
        L,pzv:sp2;
        sim,vih:char;
{----------------------------------------------------------------------------}
procedure insp (ins:char;element:sp2);
var q:sp2;
        begin
        new(q);
        q^.elem:=ins;
        q^.next:=element^.next;
        q^.before:=element^.next^.before;
        element^.next^.before:=q;
        element^.next:=q
        end;

{----------------------------------------------------------------------------}
procedure outend (m:sp2);
        begin
        while m^.before<>nil do
                begin
                m:=m^.before;
                write (m^.elem)
                end
        end;
{----------------------------------------------------------------------------}
procedure delsp (l:sp2);
var q:sp2;
        begin
        while l^.elem<>' ' do
                begin
                q:=l;
                l^.next^.before:=l^.before;
                l^.before^.next:=l^.next;
                dispose (q)
                end
        end;
{----------------------------------------------------------------------------}
begin
repeat
        writeln ('input list:');
        writeln ('space is not to be inputed');
        new(L);
        pzv:=L;
        pzv^.next:=pzv;
        pzv^.before:=pzv;
        pzv^.elem:=' ';
        ring:=pzv;
        read (sim);
        if sim='.' then begin
                writeln ('Inputing is finished');
                writeln;
                writeln('list is empty');
                writeln;
                writeln ('Outputing is finished');
                readln
                end
        else begin
                while sim<>'.' do
                        begin
                        insp(SIM,RING^.before);
                        read (sim)
                        end;
                readln;
                l^.next^.before:=nil;
                pzv:=pzv^.next;
                writeln ('Inputing is finished');
                 writeln;
                 while pzv^.elem<> ' ' do pzv:=pzv^.next;
                 writeln ('Output inputed glist from the end');
                 outend (pzv);
                 writeln;
                 writeln ('Outputing is finished');
                 delsp (pzv)
                 end;
        dispose(ring);
        pzv:=nil;
        l:=nil;
writeln;
writeln ('Do you want to continue computings? ');
writeln ('0-no, others-yes');
readln (vih);
until vih='0';
writeln ('thank you for using my programm!');
readln
end.



