Baseline: tree as shared
This commit is contained in:
1679 files changed
+1024562
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// CALL: MATCH("ATT", "GATTACA")
|
||||
// STOPS: index
|
||||
// One bound is wrong. Every position where pattern P occurs exactly in text T.
|
||||
FUNCTION MATCH(P : STRING, T : STRING) RETURNS LIST OF INTEGER
|
||||
|
||||
// Set up
|
||||
DECLARE N : INTEGER
|
||||
DECLARE M : INTEGER
|
||||
DECLARE Matched : BOOL
|
||||
DECLARE Answer : LIST OF INTEGER
|
||||
N <- LENGTH(T)
|
||||
M <- LENGTH(P)
|
||||
|
||||
// Visit each legal start
|
||||
FOR I <- 0 TO N
|
||||
|
||||
// Test: does the pattern match here?
|
||||
Matched <- TRUE
|
||||
FOR J <- 0 TO M
|
||||
IF T[I + J] != P[J] THEN
|
||||
Matched <- FALSE
|
||||
BREAK
|
||||
ENDIF
|
||||
NEXT J
|
||||
|
||||
// Update
|
||||
IF Matched THEN
|
||||
APPEND(Answer, I)
|
||||
ENDIF
|
||||
NEXT I
|
||||
|
||||
RETURN Answer
|
||||
ENDFUNCTION
|
||||
Reference in new issue
Block a user