fix: Remove unnecessary if in Search[While] algorithm
This commit is contained in:
parent
d417d52d76
commit
9c743d6484
|
@ -34,12 +34,9 @@
|
|||
\caption{Search an element in an array using a while loop (bis)}
|
||||
\begin{algorithmic}[1]
|
||||
\Function{Search}{A: Array(n), E: element}
|
||||
\Comment{Version prefered by the professor}
|
||||
\Comment{Version ``preffered" by the professor}
|
||||
\State $i \gets 0$
|
||||
\While {$i < n$ and $A[i] \neq E$}
|
||||
\If {A[i] $ = $ E}
|
||||
\State \Return \True
|
||||
\EndIf
|
||||
\State $i \gets i + 1$
|
||||
\EndWhile
|
||||
\If {$i = n$}
|
||||
|
@ -100,21 +97,21 @@
|
|||
\State $i \gets 0$
|
||||
\State $j \gets 0$
|
||||
\While {$i < n$}
|
||||
\If{$S[i] = M[i]$}
|
||||
\State $i \gets i + 1$
|
||||
\State $j \gets j + 1$
|
||||
\EndIf
|
||||
\If {$j = m$}
|
||||
\State $c \gets c + 1$
|
||||
\State $j \gets table[j-1]$
|
||||
\ElsIf {$j < n$ and $M[j] \neq S[i]$}
|
||||
\If {$j \neq 0$}
|
||||
\State $j \gets table[j-1]$
|
||||
\Else
|
||||
\State $i \gets i + 1$
|
||||
\EndIf
|
||||
\EndIf`
|
||||
\EndWhile
|
||||
\If{$S[i] = M[i]$}
|
||||
\State $i \gets i + 1$
|
||||
\State $j \gets j + 1$
|
||||
\EndIf
|
||||
\If {$j = m$}
|
||||
\State $c \gets c + 1$
|
||||
\State $j \gets table[j-1]$
|
||||
\ElsIf {$j < n$ and $M[j] \neq S[i]$}
|
||||
\If {$j \neq 0$}
|
||||
\State $j \gets table[j-1]$
|
||||
\Else
|
||||
\State $i \gets i + 1$
|
||||
\EndIf
|
||||
\EndIf`
|
||||
\EndWhile
|
||||
\State \Return $c$
|
||||
\EndFunction
|
||||
|
||||
|
@ -123,18 +120,18 @@
|
|||
\State $previous \gets 0$
|
||||
\State $table \gets $ array of zeros of size m
|
||||
\For {$i = 0$; $i < m$; $i++$}
|
||||
\If {$M[i] = M[previous]$}
|
||||
\State $previous \gets previous + 1$
|
||||
\State $table[i] \gets previous$
|
||||
\State $i \gets i + 1$
|
||||
\Else
|
||||
\If {$previous = 0$}
|
||||
\State $previous \gets table[previous - 1]$
|
||||
\Else
|
||||
\State $table[i] \gets 0$
|
||||
\State $i \gets 1$
|
||||
\EndIf
|
||||
\EndIf
|
||||
\If {$M[i] = M[previous]$}
|
||||
\State $previous \gets previous + 1$
|
||||
\State $table[i] \gets previous$
|
||||
\State $i \gets i + 1$
|
||||
\Else
|
||||
\If {$previous = 0$}
|
||||
\State $previous \gets table[previous - 1]$
|
||||
\Else
|
||||
\State $table[i] \gets 0$
|
||||
\State $i \gets 1$
|
||||
\EndIf
|
||||
\EndIf
|
||||
\EndFor
|
||||
\EndFunction
|
||||
\end{algorithmic}
|
||||
|
|
Loading…
Reference in New Issue