uses crt;
const elemen=100;
type stack = string[elemen];
tumpukan = record
isi :stack;
atas : 0..elemen;
end;
var t : tumpukan;
i, k, l, m : integer;
kalimat,word : stack;
procedure awalan(var t:tumpukan);
begin
t.atas := 0;
end;
procedure push(var t:tumpukan; x:char);
begin
t.atas := t.atas + 1;
t.isi[t.atas] := x;
end;
function pop(var t:tumpukan):char;
begin
pop := t.isi[t.atas];
t.atas := t.atas - 1;
end;
{program utama}
begin
clrscr;
awalan(t);
write('Ketik Kalimat : '); readln(kalimat);
writeln('=======================================');
writeln('Kalimat Yang Diinput : ',kalimat);
writeln;
write('Setelah Proses, Perubahannya adalah : ');
for i := 1 to length(kalimat) do
begin
if(kalimat[i]=' ') then
begin
for k:=(i-1) downto 1 do
word := word + kalimat[k];
word := word + kalimat[i];
end;
i := length(word);
if i= length(kalimat) then
begin
for i := length(kalimat) downto 1 do
word := word + kalimat[i];
end;
end;
for i := 1 to (length(kalimat)+ 1) do
push(t,word[i]);
for i:= 1 to (length(kalimat)+ 1) do
write(pop(t));
readln;
end.
Tidak ada komentar:
Posting Komentar