RosettaCodeData/Task/Remove-duplicate-elements/XPL0/remove-duplicate-elements.xpl0

25 lines
1.0 KiB
Plaintext

code Text=12; \built-in routine to display a string of characters
string 0; \use zero-terminated strings (not MSb terminated)
func StrLen(S); \Return number of characters in an ASCIIZ string
char S;
int I;
for I:= 0, -1>>1-1 do \(limit = 2,147,483,646 if 32 bit, or 32766 if 16 bit)
if S(I) = 0 then return I;
func Unique(S); \Remove duplicate bytes from string
char S;
int I, J, K, L;
[L:= StrLen(S); \string length
for I:= 0 to L-1 do \for all characters in string...
for J:= I+1 to L-1 do \scan rest of string for duplicates
if S(I) = S(J) then \if duplicate then
[for K:= J+1 to L do \ shift rest of string down (including
S(K-1):= S(K); \ terminating zero)
L:= L-1 \ string is now one character shorter
];
return S; \return pointer to string
];
Text(0, Unique("Pack my box with five dozen liquor jugs."))