Skip to content
Snippets Groups Projects
Commit 9a29ace9 authored by Peter Gerwinski's avatar Peter Gerwinski
Browse files

Korrektur 16.9.2018: durchgestrichener Text

parent bfc50dc0
Branches
No related tags found
No related merge requests found
No preview for this file type
......@@ -336,7 +336,7 @@
Ab C++11: \lstinline{constexpr}-Funktionen\\%\pause\\
{\color{red}\dots\ anscheinend auch ohne "`constexpr"' \dots}\\
darf nur aus einem einzigen \lstinline{return}-Statement bestehen\\
\textarrow\ keine Schleife {-- \color{red}\strikeout{oder vielleicht doch} außer ab C++14 --}, aber Rekursion erlaubt
\textarrow\ keine Schleife {-- \color{red}\st{oder vielleicht doch} außer ab C++14 --}, aber Rekursion erlaubt
\pause
\item
leere Parameterliste: \lstinline{void} optional\\
......@@ -477,66 +477,6 @@
\end{picture}
\end{frame}
\subsection{Namensräume}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello, world!" << endl;
return 0;
}
\end{lstlisting}
% \pause
\bigskip
\begin{lstlisting}
namespace my_output
{
...
}
using namespace my_output;
\end{lstlisting}
\end{frame}
\subsection{Objekte}
\begin{frame}[fragile]
\showsubsection
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
¡struct TBase
{
};¿
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=8]
¡struct TInteger: public TBase
{
int content;
};¿
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
¡struct TString: public TBase
{
char *content;
};¿
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
......@@ -555,8 +495,8 @@
\item[2.2] Elementare Neuerungen gegenüber C
\item[2.3] Referenz-Typen
\item[2.4] Überladbare Operatoren und Funktionen
\item[2.5] Namensräume
\color{red}
\item[2.5] Namensräume
\item[2.6] Objekte
\end{itemize}
\item[\textbf{3}] \textbf{Datenorganisation}
......
File added
% ad-20180419.pdf - Lecture Slides on Algorithms and Data Structures in C/C++
% Copyright (C) 2018 Peter Gerwinski
%
% This document is free software: you can redistribute it and/or
% modify it either under the terms of the Creative Commons
% Attribution-ShareAlike 3.0 License, or under the terms of the
% GNU General Public License as published by the Free Software
% Foundation, either version 3 of the License, or (at your option)
% any later version.
%
% This document is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this document. If not, see <http://www.gnu.org/licenses/>.
%
% You should have received a copy of the Creative Commons
% Attribution-ShareAlike 3.0 Unported License along with this
% document. If not, see <http://creativecommons.org/licenses/>.
% README: Einführung in C++, Objekte
\documentclass[10pt,t]{beamer}
\usepackage{pgslides}
\usepackage{tikz}
\usepackage{soul}
\newcommand{\underconstruction}{%
\begin{picture}(0,0)
\color{black}
\put(7,-2.2){\makebox(0,0)[b]{\includegraphics[width=1.5cm]{Zeichen_123.pdf}}}
\put(7,-2.5){\makebox(0,0)[t]{\shortstack{Änderungen\\vorbehalten}}}
\end{picture}}
\title{Algorithmen und Datenstrukturen in C/C++}
\author{Prof.\ Dr.\ rer.\ nat.\ Peter Gerwinski}
\date{19.\ April 2018}
\begin{document}
\maketitleframe
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{\dots}
\end{itemize}
\begin{picture}(0,0)(-2,-0.5)
\put(0.5,-1.0){\mbox{\Large$\mathcal{O}(n\log n)$}}
\put(0.6,-2.7){\mbox{\large\bf B-Baum}}
\put(-1.3,-3.4){\mbox{\small\it verkettete Liste}}
\put(1.5,-4.0){\mbox{\large Datenbanken}}
\put(-1.0,-1.9){\mbox{\large\tt struct}}
\put(3.0,-2.0){\mbox{\large Wegfindung}}
\put(4.0,-3.0){\mbox{Verschlüsseln}}
\put(5.7,-4.2){\mbox{\it Datenkompression}}
\put(6.0,-1.5){\mbox{CORDIC}}
\put(8.5,-2.0){\mbox{\small\bf FFT}}
\put(7.5,-2.9){\mbox{\small\tt pointer}}
\put(3.5,-0.5){\mbox{\it Rasterung}}
\put(7.7,-0.7){\mbox{\tt array}}
\put(-0.5,-5.0){\mbox{digitale Signatur}}
\put(3.5,-5.2){\mbox{\large Hash-Tabelle}}
\put(0.0,-6.3){\mbox{\small\bf kryptographische Hash-Funktion}}
\put(6.5,-6.0){\mbox{\it Prüfsumme}}
\end{picture}
\end{frame}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\item[\textbf{3}] \textbf{Datenorganisation}
\begin{itemize}
\item Listen, Bäume, Hash-Tabellen, \dots
\end{itemize}
\item[\textbf{4}] \textbf{Datenkodierung}
\begin{itemize}
\item Fehlererkennung und -korrektur
\item Kompression
\item Kryptographie
\end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
\begin{itemize}
\item FFT, CORDIC, \dots
\end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
\begin{itemize}
\item Wegfindung, \dots
\end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\section{Einführung}
\begin{frame}
\showsection
\textbf{Algorithmen}
\begin{itemize}
\smallskip
\item
Beispiele: \url{https://de.wikipedia.org/wiki/Liste_von_Algorithmen}
\medskip
\item
Häufig: "`Wie würde ein Mensch es machen?"'
\item
Beispiel: Insertionsort
\medskip
\item
Ausnahme: Überblick behalten
\item
Beispiel: Rekursion
\item
Beispiel: Stundenplanprogramm
\end{itemize}
\bigskip
\textbf{Datenstrukturen}
\begin{itemize}
\item
Modellierung (UML)
\item
Beispiel: Optimierungspotential der Datenstrukturen\\
in einem Computerspiel (592 Zeilen Python)
\end{itemize}
\end{frame}
\nosectionnonumber{\large\bf Übungsaufgabe: Verkettete Listen}
\begin{frame}
\shownosectionnonumber
Schreiben Sie eine Funktion, die eine verkettete Liste\\
in umgekehrter Reihenfolge ausgibt.
\begin{enumerate}[\quad(a)]
\item
Die Funktion soll möglichst schnell arbeiten.\\
Auf den Speicherverbrauch kommt es nicht an.
\item
Die Funktion soll möglichst wenig Speicher verbrauchen.\\
Auf die Rechenzeit kommt es nicht an.
\item
Finden Sie einen Kompromiß zwischen (a) und (b).
\end{enumerate}
Geben Sie für alle Funktionen das Landau-Symbol\\
für die Laufzeit und für den Speicherverbrauch an.
\bigskip
Hinweis zu (a): Man kann es rekursiv machen.
\end{frame}
\section{Einführung in C++}
\addtocounter{subsection}{-1}
\subsection{Was ist C?}
\begin{frame}
\showsection
\showsubsection
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kleinster gemeinsamer Nenner für viele Plattformen\\
\begin{picture}(0,1)
\color{red}
\put(7.2,0.6){\tikz{\draw[-latex](0.0,0.0)--(0.0,0.4);}}
\put(7.2,0.5){\makebox(0,0)[t]{\color{black}Hardware und/oder Betriebssystem}}
\end{picture}
\item
Hardware direkt ansprechen und effizient einsetzen
\item
\dots\ bis hin zu komplexen Software-Projekten
\medskip
\arrowitem
Man kann Computer vollständig beherrschen.
\end{itemize}
\end{frame}
\begin{frame}
\showsection
\showsubsection
\begin{picture}(0,0)
\put(5.3,-2.5){\makebox(0,0)[tl]{\begin{minipage}{7cm}
\emph{C makes it easy to shoot yourself in the foot.}
\begin{flushright}
Bjarne Stroustrup, ca.~1986\\
\href{http://www.stroustrup.com/bs_faq.html\#really-say-that}%
{\nolinkurl{http://www.stroustrup.com/bs_faq.html}\\
\nolinkurl{\#really-say-that}}
\end{flushright}
\end{minipage}}}
\end{picture}%
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kleinster gemeinsamer Nenner für viele Plattformen
\item
Hardware direkt ansprechen und effizient einsetzen
\item
\dots\ bis hin zu komplexen Software-Projekten
\item
leistungsfähig, aber gefährlich
\end{itemize}
\medskip
"`High-Level-Assembler"'
\begin{itemize}
\item
kein "`Fallschirm"'
\item
kompakte Schreibweise
\end{itemize}
\medskip
Unix-Hintergrund
\begin{itemize}
\item
Baukastenprinzip
\item
konsequente Regeln
\item
kein "`Fallschirm"'
\end{itemize}
\end{frame}
\subsection{Was ist C++?}
\begin{frame}
\showsection
\showsubsection
\begin{picture}(0,0)
\put(6.3,-0.2){\makebox(0,0)[tl]{\begin{minipage}{6cm}
\emph{C++ is a better C.}
\begin{flushright}
Bjarne Stroustrup, Autor von C++\\
\url{http://www.stroustrup.com/C++.html}
\end{flushright}
\end{minipage}}}
\put(5.3,-2.5){\makebox(0,0)[tl]{\begin{minipage}{7cm}
\emph{C makes it easy to shoot yourself in the foot;\\
C++ makes it harder, but when you do\\
it blows your whole leg off.}
\begin{flushright}
Bjarne Stroustrup, Autor von C++, ca.~1986\\
\href{http://www.stroustrup.com/bs_faq.html\#really-say-that}%
{\nolinkurl{http://www.stroustrup.com/bs_faq.html}\\
\nolinkurl{\#really-say-that}}
\end{flushright}
\end{minipage}}}
\end{picture}%
Etabliertes Profi-Werkzeug
\begin{itemize}
\item
kompatibel zu C
\end{itemize}
\medskip
C++ unterstützt
\begin{itemize}
\item
\newterm{objektorientierte\\
Programmierung}
\item
\newterm{Datenabstraktion}
\item
\newterm{generische\\
Programmierung}
\end{itemize}
\vspace{0cm plus 1 filll}
\textbf{Motivation:}\\[\smallskipamount]
Vermeidung unsicherer Techniken,\\
insbesondere von Präprozessor-Konstruktionen und Zeigern,\\
unter Beibehaltung der Effizienz
\end{frame}
\subsection{Elementare Neuerungen gegenüber C}
\begin{frame}[fragile]
\showsubsection
\begin{itemize}
\pause
\item
Kommentare mit \lstinline{//}
\pause
\item
Konstante:
\begin{onlyenv}<3>
\begin{lstlisting}[gobble=10]
const int answer = 42;
\end{lstlisting}
\end{onlyenv}
\pause
\begin{lstlisting}[gobble=8]
const int n = 5;
int prime[n] = { 2, 3, 5, 7, 11 };
\end{lstlisting}
\pause
\item
Ab C++11: \lstinline{constexpr}-Funktionen\\%\pause\\
{\color{red}\dots\ anscheinend auch ohne "`constexpr"' \dots}\\
darf nur aus einem einzigen \lstinline{return}-Statement bestehen\\
\textarrow\ keine Schleife {-- \color{red}\st{oder vielleicht doch} außer ab C++14 --}, aber Rekursion erlaubt
\pause
\item
leere Parameterliste: \lstinline{void} optional\\
\pause
in C: ohne \lstinline{void} = Parameterliste wird nicht geprüft
\pause
\item
Operatoren \lstinline{new} und \lstinline{delete}\\
als Alternative zu den Funktionen \lstinline{malloc()} und \lstinline{free()}
\end{itemize}
\end{frame}
\subsection{Referenz-Typen}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
void calc_answer (int &answer)
{
answer = 42;
}
\end{lstlisting}
\medskip
\dots\ als Alternative zu \dots
\medskip
\begin{lstlisting}
void calc_answer (int *answer)
{
*answer = 42;
}
\end{lstlisting}
\begin{itemize}
\item
Zeiger "`verborgen"', übersichtlicher und sicherer
\item
Es gibt keinen \lstinline{NULL}-Wert.\\
\textarrow\ Für verkettete Listen u.\,ä.: Tricks erforderlich
\end{itemize}
\end{frame}
\subsection{Überladbare Operatoren und Funktionen}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <iostream>
int main ()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}
\end{lstlisting}
% \pause
\bigskip
Bemerkungen:
\begin{itemize}
\item
Compilieren mit \lstinline[style=cmd]{g++}
statt \lstinline[style=cmd]{gcc}:\\
C++-Bibliotheken mit einbinden
\item
Der Operator \lstinline{<<} hat normalerweise keinen Seiteneffekt,
hier schon.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <iostream>
struct vector
{
double x, y, z;
};
vector operator + (vector u, vector v)
{
vector w = { u.x + v.x, u.y + v.y, u.z + v.z };
return w;
}
\end{lstlisting}
\begin{itemize}
\item
\lstinline{++} wird zum Präfix-Operator.
\item
\lstinline{++} mit zusätzlichem (ungenutzten) \lstinline{int}-Parameter\\
wird zum Postfix-Operator.
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
void print (const char *s)
{
printf ("%s", s);
}
void print (int i)
{
printf ("%d", i);
}
\end{lstlisting}
% \pause
\bigskip
Optionale Parameter:
\medskip
\begin{lstlisting}
void print (const char *s = "\n")
{
printf ("%s", s);
}
\end{lstlisting}
% \pause
\begin{picture}(0,0)
\color{red}
\put(5.50,5.40){\makebox(0,0)[br]{\tikz{\draw[-latex](0.0,0.0)--(-2.0,0.6);}}}
\put(5.50,4.85){\makebox(0,0)[tr]{\tikz{\draw[-latex](0.0,0.0)--(-2.0,-0.2);}}}
\put(5.6,5.0){\begin{minipage}{5cm}
Für den Linker:\\
veränderte, eindeutige Namen
\end{minipage}}
\put(5.50,1.55){\makebox(0,0)[tr]{\tikz{\draw[-latex](0.0,0.0)--(-0.6,0.4);}}}
\put(5.6,1.0){\begin{minipage}{5cm}
wird vom Compiler erledigt
\end{minipage}}
% \pause
\put(7.0,3.6){\makebox(0,0)[b]{\tikz{\draw[-latex](0.0,0.0)--(0.0,0.9);}}}
\put(5.6,3.0){\begin{minipage}{5cm}
Wenn man das nicht will:\\
extern \char`"C\char`"\ \{ \dots \}
\end{minipage}}
\end{picture}
\end{frame}
\subsection{Namensräume}
\begin{frame}[fragile]
\showsubsection
\begin{lstlisting}
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello, world!" << endl;
return 0;
}
\end{lstlisting}
% \pause
\bigskip
\begin{lstlisting}
namespace my_output
{
...
}
using namespace my_output;
\end{lstlisting}
\end{frame}
\subsection{Objekte}
\begin{frame}[fragile]
\showsubsection
\begin{center}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
¡struct TBase
{
};¿
\end{lstlisting}
\end{minipage}\\[0.5cm]
\begin{minipage}{6cm}
\begin{lstlisting}[gobble=8]
¡struct TInteger: public TBase
{
int content;
};¿
\end{lstlisting}
\end{minipage}
\begin{minipage}{5cm}
\begin{lstlisting}[gobble=8]
¡struct TString: public TBase
{
char *content;
};¿
\end{lstlisting}
\end{minipage}
\end{center}
\end{frame}
\nosectionnonumber{\inserttitle}
\begin{frame}
\shownosectionnonumber
\begin{itemize}
\item[\textbf{1}] \textbf{Einführung}
\underconstruction
\hfill\makebox(0,0)[br]{\raisebox{2.25ex}{\url{https://gitlab.cvh-server.de/pgerwinski/ad.git}}}
\item[\textbf{2}] \textbf{Einführung in C++}
\begin{itemize}
\color{medgreen}
\item[2.0] Einführung in C
\item[2.1] Einführung in C++
\item[2.2] Elementare Neuerungen gegenüber C
\item[2.3] Referenz-Typen
\item[2.4] Überladbare Operatoren und Funktionen
\item[2.5] Namensräume
\color{red}
\item[2.6] Objekte
\end{itemize}
\item[\textbf{3}] \textbf{Datenorganisation}
% \begin{itemize}
% \item Listen, Bäume, Hash-Tabellen, \dots
% \end{itemize}
\item[\textbf{4}] \textbf{Datenkodierung}
% \begin{itemize}
% \item Fehlererkennung und -korrektur
% \item Kompression
% \item Kryptographie
% \end{itemize}
\item[\textbf{5}] \textbf{Hardwarenahe Algorithmen}
% \begin{itemize}
% \item FFT, CORDIC, \dots
% \end{itemize}
\item[\textbf{6}] \textbf{Optimierung}
% \begin{itemize}
% \item Wegfindung, \dots
% \end{itemize}
\color{gray}
\item[\textbf{7}] \textbf{Numerik}
\end{itemize}
\end{frame}
\end{document}
../common/logo-hochschule-bochum-cvh-text.pdf
\ No newline at end of file
../common/logo-hochschule-bochum.pdf
\ No newline at end of file
../common/pgslides.sty
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment