fix: Remove unnecessary if in Search[While] algorithm

This commit is contained in:
Samuel Ortion 2024-03-08 08:00:05 +01:00
parent d417d52d76
commit 9c743d6484
3 changed files with 28 additions and 33 deletions

View File

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

BIN
main.pdf

Binary file not shown.

View File

@ -80,8 +80,6 @@
\input{content/chapters/include} \input{content/chapters/include}
\chapter{}
% \input{content/conclusion} % \input{content/conclusion}