| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- Listing:
- 1 MODULE prog4;
- 2 (* This program displays the permutations of a string
- 3 in alphabetic order *)
- 4 IMPORT IO,Str;
- 5
- 6 TYPE StringType = ARRAY [0..9] OF CHAR;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 7
- 8 PROCEDURE NextPerm(n:CARDINAL;
- 9 VAR s:StringType;
- 10 VAR wrap:BOOLEAN);
- 11 (* This procedure updates s to the next permutation of the
- 12 first n characters of s. The sequence of permutations
- 13 generated by successive calls is in 'dictionary' order.
- 14 If s is the last string in the sequence, the first is
- 15 returned. The boolean result wrap is used to indicate
- 16 this event *)
- 17 VAR
- 18 i:CARDINAL; (* s[i-1] is the most significant char changed *)
- 19 j:CARDINAL; (* s[j] is the char to be swapped with s[i-1] *)
- 20 tmp:CHAR;
- 21
- 22 BEGIN
- 23 IF n = 0 THEN
- 24 wrap := TRUE;
- 25 RETURN;
- 26 END;
- 27 i := n - 1;
- 28 LOOP
- 29 IF i = 0 THEN
- 30 wrap := TRUE;
- 31 EXIT;
- 32 END;
- 33 IF s[i-1] < s[i] THEN
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 34 j := n - 1;
- 35 WHILE s[j] <= s[i-1] DO
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 36 j := j - 1;
- 37 END;
- 38 tmp := s[j]; s[j] := s[i-1]; s[i-1] := tmp; (* swap *)
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 39 wrap := FALSE;
- 40 EXIT;
- 41 END;
- 42 i := i - 1;
- 43 END;
- 44 (* s[i]..s[n-1] are in reverse order, reversing them
- 45 yields the minimum permutation we require *)
- 46 j := n - 1;
- 47 WHILE i < j DO
- 48 tmp := s[j]; s[j] := s[i]; s[i] := tmp;
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 49 i := i + 1;
- 50 j := j - 1;
- 51 END;
- 52 END NextPerm;
- ***** ^ not supported yet
- 53
- 54 VAR InputString:StringType;
- ***** ^ not supported yet
- 55 wrap:BOOLEAN;
- 56 online:CARDINAL; (* number of strings in output line *)
- 57 len:CARDINAL;
- 58 BEGIN
- 59 IO.WrStr('Enter string : ');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 60 IO.RdStr(InputString);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 61
- 62 len := Str.Length(InputString);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 63 REPEAT
- 64 NextPerm(len,InputString,wrap);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 65 UNTIL wrap;
- 66
- 67 online := 0;
- 68 REPEAT
- 69 IO.WrStr(InputString);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 70 IO.WrStr(' ');
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 71 online := online + 1;
- 72 IF online = 6 THEN
- 73 IO.WrLn;
- ***** ^ not supported yet
- ***** ^ not supported yet
- 74 online := 0;
- 75 END;
- 76 NextPerm(len,InputString,wrap);
- ***** ^ not supported yet
- ***** ^ not supported yet
- ***** ^ not supported yet
- 77 UNTIL wrap;
- 78 END prog4.
- 79
- 51 errors
|