Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
25
Task/Search-a-list/XPL0/search-a-list.xpl0
Normal file
25
Task/Search-a-list/XPL0/search-a-list.xpl0
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
\Based on C example:
|
||||
include c:\cxpl\stdlib; \provides StrCmp routine, etc.
|
||||
int Haystack; \('int' is used instead of 'char' for 2D array)
|
||||
|
||||
func Search(Str, First); \Return first (or last) index for string in haystack
|
||||
char Str; int First;
|
||||
int I, SI;
|
||||
[I:= 0; SI:= 0;
|
||||
repeat if StrCmp(Str, Haystack(I)) = 0 then
|
||||
[if First then return I;
|
||||
SI:= I; \save index
|
||||
];
|
||||
I:= I+1;
|
||||
until Haystack(I) = 0;
|
||||
return SI;
|
||||
];
|
||||
|
||||
[Haystack:= ["Zig", "Zag", "Wally", "Ronald", "Bush",
|
||||
"Krusty", "Charlie", "Bush", "Boz", "Zag", 0];
|
||||
Text(0, "Bush is at "); IntOut(0, Search("Bush", true)); CrLf(0);
|
||||
if Search("Washington", true) = 0 then
|
||||
Text(0, "Washington is not in the haystack^M^J");
|
||||
Text(0, "First index for Zag: "); IntOut(0, Search("Zag", true)); CrLf(0);
|
||||
Text(0, "Last index for Zag: "); IntOut(0, Search("Zag", false)); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue