\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{TimSch} \pdfinfo{ /Title (listen.pdf) /Creator (Cheatography) /Author (TimSch) /Subject (Listen Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{Listen Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{TimSch} via \textcolor{DarkBackground}{\uline{cheatography.com/29480/cs/15163/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}TimSch \\ \uline{cheatography.com/timsch} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 18th March, 2018.\\ Updated 18th March, 2018.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{2} \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Einfach verkettete Listen}} \tn % Row 0 \SetRowColor{LightBackground} Datenstruktur definieren & `typedef struct sData \{\{nl\}\} \{ \{\{nl\}\} ~ int Index; \{\{nl\}\} ~ double Value; \{\{nl\}\} ~ struct sData *Next; \{\{nl\}\}\};` \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} Globale Zeiger auf Listenanfang und Listenende & `{\emph{extern}} TData *First = NULL; \{\{nl\}\} {\emph{extern}} TData *Last = NULL;` \{\{nl\}\}Schlüsselwort extern, damit die Zeiger über alle Quelltextdateien verfügbar sind. Alternativ in main definieren. \tn % Row Count 17 (+ 10) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{8.4cm}}{\{\{ac\}\}{\bf{Funktionen (bspw. in list.c/h auslagern)}}} \tn % Row Count 18 (+ 1) % Row 3 \SetRowColor{white} Neues Element anh{\"a}ngen & `int appendInList(TData *Neu) \{\{nl\}\} \{ \{\{nl\}\} ~ //prüfen, ob neues Element existiert \{\{nl\}\} ~ if (Neu == NULL) \{\{nl\}\} ~ ~ return 0; \{\{nl\}\} \{\{nl\}\} ~ //Neues Element ist neues Listenende \{\{nl\}\} ~ Neu-\textgreater{}Next = NULL; \{\{nl\}\} \{\{nl\}\} ~ if (First == NULL) \{\{nl\}\} ~ ~ //Fall 1: Liste ist leer \{\{nl\}\} ~ ~ First = Last = Neu; \{\{nl\}\} ~ else \{\{nl\}\} ~ ~ //Fall 2: Liste ist nicht leer \{\{nl\}\} ~ ~ Last = Last-\textgreater{}Next = Neu; \{\{nl\}\} ~ return 1; \{\{nl\}\} \}` \tn % Row Count 45 (+ 27) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Einfach verkettete Listen (cont)}} \tn % Row 4 \SetRowColor{LightBackground} Neues Element (sortiert) einfügen & `int insertInList(TData *Neu) \{\{nl\}\} \{ \{\{nl\}\} ~ TData *tmp = First; \{\{nl\}\} ~ //prüfen, ob neues Element existiert \{\{nl\}\} ~ if(Neu == NULL) \{\{nl\}\} ~ ~ return 0; \{\{nl\}\} ~ if(First == NULL) \{\{nl\}\} ~ \{ //Fall 1: Liste ist leer \{\{nl\}\} ~ ~ Neu-\textgreater{}Next = NULL; \{\{nl\}\} ~ ~ First = Last = Neu; \{\{nl\}\} ~ ~ return 1; \{\{nl\}\} ~ \} \{\{nl\}\} ~ if (First-\textgreater{}Value \textgreater{}= Neu-\textgreater{}Value( \{\{nl\}\} ~ \{ //Fall 2: am Listenanfang einfügen \{\{nl\}\} ~ ~ Neu-\textgreater{}Next = First; \{\{nl\}\} ~ ~ First = Neu; \{\{nl\}\} ~ ~ return 1; \{\{nl\}\} ~ \} \{\{nl\}\} ~ if (Last-\textgreater{}Value \textless{}= Neu-\textgreater{}Value) \{\{nl\}\} ~ \{ //Fall 3: am Listenende anh{\"a}ngen \{\{nl\}\} ~ ~ Neu-\textgreater{}Next = NULL; \{\{nl\}\} ~ ~ Last = Last-\textgreater{}Next = Neu; \{\{nl\}\} ~ ~ return 1; \{\{nl\}\} ~ \} \{\{nl\}\} ~ //Fall 4: zwischen zwei Elemente einfügen \{\{nl\}\} ~ while (tmp-\textgreater{}Next != NULL) \{\{nl\}\} ~ \{ //prüfen, ob neues Listenelement vor dem n{\"a}chsten Listenelement eingefügt werden muss \{\{nl\}\} ~ ~ if (tmp-\textgreater{}Next-\textgreater{}Value \textgreater{}= Neu-\textgreater{}Value) \{\{nl\}\} ~ ~ \{ \{\{nl\}\} ~ ~ ~ Neu-\textgreater{}Next = tmp-\textgreater{}Next; \{\{nl\}\} ~ ~ ~ tmp-\textgreater{}Next = Neu; \{\{nl\}\} ~ ~ ~ return 1; \{\{nl\}\} ~ ~ \} \{\{nl\}\} ~ ~ return 0; \{\{nl\}\} ~ \}` \tn % Row Count 69 (+ 69) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{4 cm} x{4 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Einfach verkettete Listen (cont)}} \tn % Row 5 \SetRowColor{LightBackground} Element l{\"o}schen & `TData *removeFromList(int delIndex) \{\{nl\}\} \{ \{\{nl\}\} ~ TData {\emph{tmp = NULL, }}prev = NULL; \{\{nl\}\} ~ // Fall 1: Liste leer? \{\{nl\}\} ~ if (First == NULL) \{\{nl\}\} ~ ~ return NULL; \{\{nl\}\} \{\{nl\}\} ~ // Fall 2: Listenanfang entfernen? \{\{nl\}\} ~ if (First-\textgreater{}Index == delIndex) \{\{nl\}\} ~ \{ \{\{nl\}\} ~ ~ tmp = First; \{\{nl\}\} ~ ~ // nur ein Element in Liste? \{\{nl\}\} ~ ~ if (Last == First) \{\{nl\}\} ~ ~ ~ Last = NULL; \{\{nl\}\} ~ ~ First = First-\textgreater{}Next; \{\{nl\}\} ~ ~ return tmp; \{\{nl\}\} ~ \} \{\{nl\}\} \{\{nl\}\} ~ // Fall 3: zu entfernendes Element suchen \{\{nl\}\} ~ prev = First; \{\{nl\}\} ~ tmp = prev-\textgreater{}Next; \{\{nl\}\} ~ while (tmp != NULL) \{\{nl\}\} ~ \{ \{\{nl\}\} ~ ~ if (tmp-\textgreater{}Index == delIndex) \{\{nl\}\} ~ ~ \{ \{\{nl\}\} ~ ~ ~ prev-\textgreater{}Next = tmp-\textgreater{}Next; \{\{nl\}\} ~ ~ ~ if (tmp == Last) // letztes Element entfernt? \{\{nl\}\} ~ ~ ~ ~ Last = prev; \{\{nl\}\} ~ ~ ~ return tmp; \{\{nl\}\} ~ ~ \} \{\{nl\}\} ~ ~ prev = tmp; \{\{nl\}\} ~ ~ tmp = tmp-\textgreater{}Next; \{\{nl\}\} ~ \} \{\{nl\}\} ~ return NULL; \{\{nl\}\} \}` \tn % Row Count 62 (+ 62) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Doppelt verkettete Listen}} \tn % Row 0 \SetRowColor{LightBackground} An Liste anh{\"a}ngen & `int appendInList(TData *Neu) \{\{nl\}\} \{ \{\{nl\}\} ~ //prüfen, ob neues Element existiert \{\{nl\}\} ~ if (Neu == NULL) \{\{nl\}\} ~ ~ return 0; \{\{nl\}\} \{\{nl\}\} ~ if (First == NULL) \{\{nl\}\} ~ ~ //Fall 1: Liste ist leer \{\{nl\}\} ~ ~ Neu-\textgreater{}Next = Neu-\textgreater{}Prev = NULL; \{\{nl\}\} ~ ~ First = Last = Neu; \{\{nl\}\} ~ else \{\{nl\}\} ~ ~ //Fall 2: Liste ist nicht leer \{\{nl\}\} ~ ~ Neu-\textgreater{}Next = NULL; \{\{nl\}\} ~ ~ Neu-\textgreater{}Prev = Last; \{\{nl\}\} ~ ~ Last = Last-\textgreater{}Next = Neu; \{\{nl\}\} ~ return 1; \{\{nl\}\} \}` \tn % Row Count 28 (+ 28) % Row 1 \SetRowColor{white} In Liste (sortiert) einfügen & `int insertInList(TData *Neu) \{\{nl\}\} \{ \{\{nl\}\} ~TData *tmp = First; \{\{nl\}\} ~ \{\{nl\}\} ~//prüfen, ob neues Element existiert \{\{nl\}\} ~if(Neu == NULL) \{\{nl\}\} ~ ~return 0; \{\{nl\}\} ~ ~ \{\{nl\}\} ~if(First == NULL) \{\{nl\}\} ~\{ //Fall 1: Liste ist leer \{\{nl\}\} ~ ~Neu-\textgreater{}Next = Neu-\textgreater{}Prev = NULL; \{\{nl\}\} ~ ~First = Last = Neu; \{\{nl\}\} ~ ~return 1; \{\{nl\}\} ~\} \{\{nl\}\} ~ \{\{nl\}\} ~if (First-\textgreater{}Value \textgreater{}= Neu-\textgreater{}Value( \{\{nl\}\} ~\{ //Fall 2: am Listenanfang einfügen \{\{nl\}\} ~ ~Neu-\textgreater{}Next = First; \{\{nl\}\} ~ ~Neu-\textgreater{}Prev = NULL; \{\{nl\}\} ~ ~First = First-\textgreater{}Prev = Neu; \{\{nl\}\} ~ ~return 1; \{\{nl\}\} ~\} \{\{nl\}\} ~ \{\{nl\}\} ~if (Last-\textgreater{}Value \textless{}= Neu-\textgreater{}Value) \{\{nl\}\} ~\{ //Fall 3: am Listenende anh{\"a}ngen \{\{nl\}\} ~ ~Neu-\textgreater{}Prev = Last; \{\{nl\}\} ~ ~Neu-\textgreater{}Next = NULL; \{\{nl\}\} ~ ~Last = Last-\textgreater{}Next = Neu; \{\{nl\}\} ~ ~return 1; \{\{nl\}\} ~\} \{\{nl\}\} ~ \{\{nl\}\} ~//Fall 4: zwischen zwei Elemente einfügen \{\{nl\}\} ~while (tmp-\textgreater{}Next != NULL) \{\{nl\}\} ~\{ //prüfen, ob neues Listenelement vor dem n{\"a}chsten Listenelement eingefügt werden muss \{\{nl\}\} ~ ~if (tmp-\textgreater{}Next-\textgreater{}Value \textgreater{}= Neu-\textgreater{}Value) \{\{nl\}\} ~ ~\{ \{\{nl\}\} ~ ~ ~Neu-\textgreater{}Next = tmp-\textgreater{}Next; \{\{nl\}\} ~ ~ ~Neu-\textgreater{}Prev = temp; \{\{nl\}\} ~ ~ ~tmp-\textgreater{}Next = temp-\textgreater{}Next-\textgreater{}Prev = Neu; \{\{nl\}\} ~ ~ ~return 1; \{\{nl\}\} ~ ~\} \{\{nl\}\} ~ ~tmp = temp-\textgreater{}Next; \{\{nl\}\} ~\} \{\{nl\}\} ~return 0; \{\{nl\}\} \} ` \tn % Row Count 99 (+ 71) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Doppelt verkettete Listen (cont)}} \tn % Row 2 \SetRowColor{LightBackground} Aus Liste entfernen & `TData *removeFromList(int delIndex) \{\{nl\}\} \{ \{\{nl\}\} ~TData *tmp = NULL, *prev = NULL; \{\{nl\}\} ~// Fall 1: Liste leer? \{\{nl\}\} ~if (First == NULL) \{\{nl\}\} ~ ~return NULL; \{\{nl\}\} \{\{nl\}\} ~// Fall 2: Listenanfang entfernen? \{\{nl\}\} ~if (First-\textgreater{}Index == delIndex) \{\{nl\}\} ~\{ \{\{nl\}\} ~ ~tmp = First; \{\{nl\}\} ~ ~First = First-\textgreater{}Next; \{\{nl\}\} ~ ~// nur ein Element in Liste? \{\{nl\}\} ~ ~if (First == NULL) \{\{nl\}\} ~ ~ ~Last = NULL; \{\{nl\}\} ~ ~else \{\{nl\}\} ~ ~ ~First-\textgreater{}Prev = NULL; \{\{nl\}\} ~ ~return tmp; \{\{nl\}\} ~\} \{\{nl\}\} \{\{nl\}\} ~// Fall 3: Listenende entfernen? \{\{nl\}\} ~if (Last-\textgreater{}Index == delIndex) \{\{nl\}\} ~\{ \{\{nl\}\} ~ ~tmp = Last; \{\{nl\}\} ~ ~Last = Last-\textgreater{}Prev; \{\{nl\}\} ~ ~Last-\textgreater{}Next = NULL; \{\{nl\}\} ~ ~return tmp; \{\{nl\}\} ~\} \{\{nl\}\} ~ \{\{nl\}\} ~//Fall 4: zu entfernendes Element suchen \{\{nl\}\} ~tmp = First-\textgreater{}Next; \{\{nl\}\} ~while (tmp != NULL) \{\{nl\}\} ~\{ \{\{nl\}\} ~ ~if (tmp-\textgreater{}Index == delIndex) \{\{nl\}\} ~ ~\{ \{\{nl\}\} ~ ~ ~prev = tmp-\textgreater{}Prev; \{\{nl\}\} ~ ~ ~prev-\textgreater{}Next = tmp-\textgreater{}Next; \{\{nl\}\} ~ ~ ~prev-\textgreater{}Next-\textgreater{}Prev = prev; \{\{nl\}\} ~ ~ ~return tmp; \{\{nl\}\} ~ ~\} \{\{nl\}\} ~ ~tmp = tmp-\textgreater{}Next; \{\{nl\}\} ~\} \{\{nl\}\} ~return NULL; \{\{nl\}\} \}` \tn % Row Count 64 (+ 64) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{8.4cm}{x{3.36 cm} x{4.64 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{8.4cm}}{\bf\textcolor{white}{Doppelt verkettete Listen (cont)}} \tn % Row 3 \SetRowColor{LightBackground} Alle Elemente auflisten & ` typedef enum \{forward, backward\} TDirection; \{\{nl\}\} \{\{nl\}\} void printList(TDirection Direction) \{\{nl\}\} \{ \{\{nl\}\} ~ TData *tmp = (Direction == forward) ? First : Last; \{\{nl\}\} ~ int AnzahlElemente = 0; \{\{nl\}\} \{\{nl\}\} ~ printf("\textbackslash{}nIndex "); \{\{nl\}\} ~ while (tmp) \{\{nl\}\} ~ \{ \{\{nl\}\} ~ ~ printf("| \%3i ", tmp-\textgreater{}Index); \{\{nl\}\} ~ ~ tmp = (Direction == forward) ? tmp-\textgreater{}Next : tmp-\textgreater{}Prev; \{\{nl\}\} ~ ~ AnzahlElemente++; \{\{nl\}\} ~ \} \{\{nl\}\} \{\{nl\}\} ~ printf("\textbackslash{}n-{}-{}-{}-{}-{}-"); \{\{nl\}\} ~ while (AnzahlElemente-{}-) \{\{nl\}\} ~ ~ printf("-{}-{}-{}-{}-{}-"); \{\{nl\}\} \{\{nl\}\} ~ printf("\textbackslash{}nWert "); \{\{nl\}\} ~ tmp = (Direction == forward) ? First : Last; \{\{nl\}\} ~ while (tmp != NULL) \{\{nl\}\} ~ \{ \{\{nl\}\} ~ ~ printf("| \%3.0f ", tmp-\textgreater{}Value); \{\{nl\}\} ~ ~ tmp = (Direction == forward) ? tmp-\textgreater{}Next : tmp-\textgreater{}Prev; \{\{nl\}\} ~ \} \{\{nl\}\} ~ printf("\textbackslash{}n"); \{\{nl\}\} \}` \tn % Row Count 42 (+ 42) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}