Skip to content
Snippets Groups Projects
Commit 940e1a78 authored by Kevin Conrads's avatar Kevin Conrads
Browse files

Selection Sort eingepflegt

parent e7f5f62b
No related branches found
No related tags found
No related merge requests found
...@@ -430,27 +430,64 @@ Insertion Sort ist ein Sortierverfahren, dass jedes Element eines Arrays an die ...@@ -430,27 +430,64 @@ Insertion Sort ist ein Sortierverfahren, dass jedes Element eines Arrays an die
\textbf{Ausgabe:} Aufsteigend sortiertes Array $A$ \textbf{Ausgabe:} Aufsteigend sortiertes Array $A$
\tcblower \tcblower
\textbf{FOR} $j=1$ \textbf{TO} $n-1$ \textbf{IF} ($n=1$)
\tab $key$ = $A[j]$ \tab \textbf{RETURN} $A$
\tab $i = j-1$ Sortiere $A[1 \dots \frac{n}{2}]$ und $A[\frac{n}{2} +1 \dots n]$ rekursiv
\tab \textbf{WHILE} ($i>0$ \textbf{AND} $A[i]>key$) Merge die beiden sortierten Teilarrays
\tab\tab $A[i+1] = A[i]$ \textbf{RETURN} $A$
\end{algo}
\end{halfboxr}
\tab\tab $i =i-1$ \subsection{Selection Sort und Bubble Sort}
\tab $A[i+1] = key$ \begin{halfboxl}
\vspace{-\baselineskip}
\begin{algo}{Selection Sort}
\textbf{Eingabe:} Array der Länge $n$
\textbf{Ausgabe:} Aufsteigend sortiertes Array $A$
\tcblower
\textbf{FOR} $j=0$ \textbf{TO} $n-1$
\tab $i_{\min}$ = $j$
\tab \textbf{FOR} $i = j + 1 $ \textbf{TO} $n-1$
\tab\tab \textbf{IF} ($A[i] < A[i_{\min}]$)
\tab\tab\tab $i_{\min} = i$
\tab \textbf{IF} ($i_{\min} \neq j$)
\tab\tab Tausche $A[j]$ und $A[i_{\min}]$
\textbf{RETURN} $A$ \textbf{RETURN} $A$
\end{halfboxr} \end{algo}
\end{halfboxl}%
\begin{halfboxr}
\vspace{-\baselineskip}
\begin{algo}{Bubble Sort}
\textbf{Eingabe:} Array der Länge $n$
\textbf{Ausgabe:} Aufsteigend sortiertes Array $A$
\tcblower
\textbf{IF} ($n=1$)
TODO: Merge-Sort code einfügen \tab \textbf{RETURN} $A$
Sortiere $A[1 \dots \frac{n}{2}]$ und $A[\frac{n}{2} +1 \dots n]$ rekursiv
Merge Sort Merge die beiden sortierten Teilarrays
\textbf{RETURN} $A$
\end{algo}
\end{halfboxr}
Selection Sort Selection Sort
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment