Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Datenstrukturen und Algorithm Skript
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Automate
Agent sessions
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Unger, Florian Fedor Fridolin
Datenstrukturen und Algorithm Skript
Commits
367a82c0
Commit
367a82c0
authored
Apr 30, 2020
by
Florian Unger
Browse files
Options
Downloads
Patches
Plain Diff
added appendix with code
parent
7ad0f48f
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
901_Appendix_Code.tex
+19
-0
19 additions, 0 deletions
901_Appendix_Code.tex
Datenstrukturen_und_Algorithmen.tex
+19
-1
19 additions, 1 deletion
Datenstrukturen_und_Algorithmen.tex
code/quicksort.py
+34
-0
34 additions, 0 deletions
code/quicksort.py
with
72 additions
and
1 deletion
901_Appendix_Code.tex
0 → 100644
+
19
−
0
View file @
367a82c0
\chapter
{
Programmcode
}
\lstset
{
language=Python,
tabsize=2,
rulesepcolor=
\color
{
gray
}
,
xleftmargin=00pt,
framexleftmargin=00pt,
keywordstyle=
\color
{
blue
}
\bf
,
commentstyle=
\color
{
gray
}
,
stringstyle=
\color
{
red
}
,
numbers=left,
numberstyle=
\tiny
,
numbersep=5pt,
breaklines=true,
showstringspaces=false,
basicstyle=
\fontsize
{
7
}{
9
}
\selectfont\ttfamily
,
emph=
{
str
}
,emphstyle=
{
\color
{
magenta
}}}
\section
{
\texttt
{
quicksort
}
in Python
}
\lstinputlisting
[language=Python]
{
code/quicksort.py
}
This diff is collapsed.
Click to expand it.
Datenstrukturen_und_Algorithmen.tex
+
19
−
1
View file @
367a82c0
\documentclass
[ngerman, a4paper, oneside
]
{
scr
book
}
\documentclass
[ngerman, a4paper, oneside
, appendixprefix]
{
book
}
\usepackage
[ngerman]
{
babel
}
\usepackage
[ngerman]
{
babel
}
%encoding
%encoding
\usepackage
[utf8]
{
inputenc
}
\usepackage
[utf8]
{
inputenc
}
\usepackage
{
alphabeta
}
\usepackage
{
alphabeta
}
%appendix (copied from SE)
%\usepackage{xpatch}
%\xapptocmd{\appendix}{%
% \addtocontents{toc}{%
% \RedeclareSectionCommand[
% tocdynnumwidth,
% tocentrynumberformat=\tocappendixnumber
% ]{chapter}%
% }%
%}{}{\PatchFailed}
%\newcommand\tocappendixnumber[1]{\chapapp~#1}
%math symbols
%math symbols
\usepackage
{
amsmath
}
\usepackage
{
amsmath
}
...
@@ -29,6 +40,9 @@
...
@@ -29,6 +40,9 @@
\SetEndCharOfAlgoLine
{}
\SetEndCharOfAlgoLine
{}
\usepackage
{
textcomp
}
\usepackage
{
textcomp
}
%code listings
\usepackage
{
listings
}
%figures
%figures
\usepackage
{
subcaption
}
\usepackage
{
subcaption
}
%internal figures
%internal figures
...
@@ -45,6 +59,7 @@
...
@@ -45,6 +59,7 @@
%other
%other
\usepackage
{
scrextend
}
\usepackage
{
scrextend
}
%\usepackage{hhline}
%\usepackage{hhline}
\usepackage
{
appendix
}
%custom macros
%custom macros
\makeatletter
\makeatletter
...
@@ -62,4 +77,7 @@
...
@@ -62,4 +77,7 @@
\input
{
100
_
Grundlagen
}
\input
{
100
_
Grundlagen
}
\input
{
200
_
Sortieralgorithmen
}
\input
{
200
_
Sortieralgorithmen
}
\input
{
300
_
Datenstrukturen
}
\input
{
300
_
Datenstrukturen
}
\appendix
\input
{
901
_
Appendix
_
Code
}
\end{document}
\end{document}
This diff is collapsed.
Click to expand it.
code/quicksort.py
0 → 100644
+
34
−
0
View file @
367a82c0
def
swap
(
A
,
i
,
j
):
A
[
i
],
A
[
j
]
=
A
[
j
],
A
[
i
]
return
A
def
partition
(
A
):
p
=
A
[
-
1
]
print
(
"
A is {} as partition is called, pivot is {}
"
.
format
(
A
,
p
))
i
=
-
1
for
j
in
range
(
len
(
A
)
-
1
):
if
A
[
j
]
<=
p
:
A
=
swap
(
A
,
i
+
1
,
j
)
i
+=
1
print
(
"
A is {} after swapping i={} and j={} during partition as {} <= {}
"
.
format
(
A
,
i
,
j
,
A
[
i
],
p
))
A
=
swap
(
A
,
i
+
1
,
-
1
)
i
+=
1
print
(
"
A is {} after swapping {} and {} in final swap in partition, returning A and pivot index {} to quicksort
"
.
format
(
A
,
i
,
j
,
i
))
return
(
A
,
i
)
def
quicksort
(
A
):
print
(
"
A is {} as quicksort is called
"
.
format
(
A
))
if
len
(
A
)
>
1
:
A
,
k
=
partition
(
A
)
print
(
"
A is {} after partition, calculating now: quicksort({}) + [A[{}]] + quicksort({})
"
.
format
(
A
,
A
[:
k
],
k
,
A
[
k
+
1
:]))
return
quicksort
(
A
[:
k
])
+
[
A
[
k
]]
+
quicksort
(
A
[
k
+
1
:])
else
:
return
A
A
=
[
7
,
2
,
1
,
8
,
6
,
3
,
5
,
4
]
# see https://www.youtube.com/watch?v=MZaf_9IZCrc for step-for-step explanation of the first partition here
# A = [34,56,99,46,23,16,23,11,23,56] # a more complex case, might be helpful ...
A
=
quicksort
(
A
)
print
(
"
A was sorted to {}
"
.
format
(
A
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment