Compare commits
23 Commits
9a56c63018
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
14f59eeb63 | ||
|
|
a6cce9626c | ||
|
|
8d726bf344 | ||
|
|
04eecdb444 | ||
|
|
60c47c20c5 | ||
|
|
89499f524f | ||
|
|
e55d8708a7 | ||
|
|
ea7dfc5bef | ||
|
|
18ece75b67 | ||
|
|
6541a5246d | ||
|
|
3505401c7f | ||
|
|
b193d1d61e | ||
|
|
ae459547c2 | ||
|
|
0f1b426f94 | ||
|
|
cccc6a14ba | ||
|
|
8d2de4fa2b | ||
|
|
5c13f8d4cd | ||
| fe93d96584 | |||
| 580cc97387 | |||
| ef833533f6 | |||
| ab38c181c9 | |||
| 972027ce41 | |||
| 2d91e98904 |
@@ -88,4 +88,8 @@ parts:
|
|||||||
- command: 'algorithm-stacks-next-greater-element'
|
- command: 'algorithm-stacks-next-greater-element'
|
||||||
description: 'Seminarblatt Woche 4, Aufgabe 1'
|
description: 'Seminarblatt Woche 4, Aufgabe 1'
|
||||||
inputs:
|
inputs:
|
||||||
L: [4, 2, 1, 100, 6, 3, 16]
|
L: [4, 6, 3, 16]
|
||||||
|
- command: 'algorithm-stacks-next-greater-element'
|
||||||
|
description: 'Seminarblatt Woche 4, Aufgabe 1 mit anderen Daten'
|
||||||
|
inputs:
|
||||||
|
L: [20, 10, 10, 2, 1, 5, 30, 3, 16]
|
||||||
|
|||||||
5
code/golang/.gitignore
vendored
5
code/golang/.gitignore
vendored
@@ -18,9 +18,10 @@
|
|||||||
!/assets/LOGO
|
!/assets/LOGO
|
||||||
!/assets/config.yml
|
!/assets/config.yml
|
||||||
|
|
||||||
!/internal
|
|
||||||
!/pkg
|
!/pkg
|
||||||
!/**/*.go
|
!/internal
|
||||||
|
!/*/**/
|
||||||
|
!/*/**/*.go
|
||||||
!/go.mod
|
!/go.mod
|
||||||
!/go.sum
|
!/go.sum
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# LOCAL ARGUMENTS
|
# LOCAL ARGUMENTS
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
PATH_TO_ARTEFACT:=../../dist/ads
|
PATH_TO_CONFIG:=../config.yml#<- kann durch Pfad zur eigenen yml-Datei ersetzt werden
|
||||||
PATH_TO_CONFIG:=../config.yml
|
PATH_TO_ARTEFACT:=../../dist/ads#<- kann beliebiger Pfad sein
|
||||||
COLOUR:=true# <- auf false stellen, falls es Probleme gibt
|
COLOUR:=true
|
||||||
|
|
||||||
|
## für Windows weichen Defaultsettings leicht ab:
|
||||||
|
ifeq ($(OS),Windows_NT)
|
||||||
|
PATH_TO_ARTEFACT:=${PATH_TO_ARTEFACT}.exe
|
||||||
|
COLOUR:=false# <- man kann als 'true' setzen, aber in Windows funktioniert es möglicherweise nicht
|
||||||
|
endif
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# TARGETS
|
# TARGETS
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
X.Y.Z
|
0.0.0
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package logging
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ func Debug(line interface{}, args ...interface{}) {
|
|||||||
if !debugmode {
|
if !debugmode {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logGeneric(os.Stdout, "[\033[96;1mDEBUG\033[0m]", line, args...)
|
logGeneric(os.Stdout, "\033[2m[\033[96;1mDEBUG\033[0m\033[2m]\033[0m", fmt.Sprintf("\033[2m%v\033[0m", line), args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Warn(line interface{}, args ...interface{}) {
|
func Warn(line interface{}, args ...interface{}) {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import (
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
var _ctr_time = types.NewCounter()
|
var _ctr_time = types.NewCounter()
|
||||||
|
var _ctr_moves = types.NewCounter()
|
||||||
var _ctr_space = types.NewCounter()
|
var _ctr_space = types.NewCounter()
|
||||||
var _tmr = types.NewTimer()
|
var _tmr = types.NewTimer()
|
||||||
|
|
||||||
@@ -26,6 +27,7 @@ var _tmr = types.NewTimer()
|
|||||||
|
|
||||||
func ResetMetrics() {
|
func ResetMetrics() {
|
||||||
_ctr_time.Reset()
|
_ctr_time.Reset()
|
||||||
|
_ctr_moves.Reset()
|
||||||
_ctr_space.Reset()
|
_ctr_space.Reset()
|
||||||
_tmr.Reset()
|
_tmr.Reset()
|
||||||
}
|
}
|
||||||
@@ -42,14 +44,26 @@ func AddTimeCost(options ...int) {
|
|||||||
_ctr_time.Add(options...)
|
_ctr_time.Add(options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func AddMovesCost(options ...int) {
|
||||||
|
_ctr_moves.Add(options...)
|
||||||
|
}
|
||||||
|
|
||||||
func AddSpaceCost(options ...int) {
|
func AddSpaceCost(options ...int) {
|
||||||
_ctr_space.Add(options...)
|
_ctr_space.Add(options...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetSpaceCost(n int) {
|
||||||
|
_ctr_space.Set(n)
|
||||||
|
}
|
||||||
|
|
||||||
func GetTimeCost() int {
|
func GetTimeCost() int {
|
||||||
return _ctr_time.Size()
|
return _ctr_time.Size()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMovesCost() int {
|
||||||
|
return _ctr_moves.Size()
|
||||||
|
}
|
||||||
|
|
||||||
func GetSpaceCost() int {
|
func GetSpaceCost() int {
|
||||||
return _ctr_space.Size()
|
return _ctr_space.Size()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,7 +68,10 @@ var optionsConfigFile = argparse.Options{
|
|||||||
// Parst cli flags.
|
// Parst cli flags.
|
||||||
func ParseCli(args []string) (*types.CliArguments, error) {
|
func ParseCli(args []string) (*types.CliArguments, error) {
|
||||||
var err error
|
var err error
|
||||||
Parser = argparse.NewParser("cli parser", "Liest Optionen + Flags von Kommandozeile.")
|
Parser = argparse.NewParser(
|
||||||
|
"cli parser",
|
||||||
|
"\033[93;2mEin Programm zur Ausführung verschiedener Algorithmen aus dem Kurs AlgoDat I.\033[0m",
|
||||||
|
)
|
||||||
arguments := types.CliArguments{
|
arguments := types.CliArguments{
|
||||||
ModeHelp: Parser.NewCommand("help", "Hilfsanleitung anzeigen"),
|
ModeHelp: Parser.NewCommand("help", "Hilfsanleitung anzeigen"),
|
||||||
ModeVersion: Parser.NewCommand("version", "Version anzeigen."),
|
ModeVersion: Parser.NewCommand("version", "Version anzeigen."),
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ func ReadAsset(key string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
* METHODS templates
|
* METHODS assets
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func Help() string {
|
func Help() string {
|
||||||
|
|||||||
@@ -104,6 +104,7 @@ func DisplayMetrics() {
|
|||||||
// logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsed())
|
// logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsed())
|
||||||
logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat())
|
logging.Plain("Dauer der Ausführung: t = \033[1m%[1]v\033[0m", metrics.GetTimeElapsedLongFormat())
|
||||||
logging.Plain("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetTimeCost()))
|
logging.Plain("Kosten (Zeit): T(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetTimeCost()))
|
||||||
|
logging.Plain("Kosten (#Züge): M(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetMovesCost()))
|
||||||
logging.Plain("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetSpaceCost()))
|
logging.Plain("Kosten (Platz): S(n) = \033[1m%[1]v\033[0m", displayCost(metrics.GetSpaceCost()))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ func (self Counter) Size() int {
|
|||||||
return self.nr
|
return self.nr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *Counter) Reset() {
|
||||||
|
self.nr = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *Counter) Set(n int) {
|
||||||
|
self.nr = n
|
||||||
|
}
|
||||||
|
|
||||||
func (self *Counter) Add(options ...int) {
|
func (self *Counter) Add(options ...int) {
|
||||||
n := 1
|
n := 1
|
||||||
if len(options) > 0 {
|
if len(options) > 0 {
|
||||||
@@ -46,7 +54,3 @@ func (self *Counter) Add(options ...int) {
|
|||||||
}
|
}
|
||||||
self.nr += n
|
self.nr += n
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Counter) Reset() {
|
|
||||||
self.nr = 0
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -38,9 +38,11 @@ var (
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var err error
|
|
||||||
var arguments *types.CliArguments
|
var arguments *types.CliArguments
|
||||||
var (
|
var (
|
||||||
|
err1 error
|
||||||
|
err2 error
|
||||||
|
err3 error
|
||||||
cmdMissing bool
|
cmdMissing bool
|
||||||
showChecks bool
|
showChecks bool
|
||||||
)
|
)
|
||||||
@@ -50,12 +52,12 @@ func main() {
|
|||||||
setup.Assets = assets
|
setup.Assets = assets
|
||||||
|
|
||||||
// cli arguments parsen
|
// cli arguments parsen
|
||||||
arguments, err = cli.ParseCli(os.Args)
|
arguments, err1 = cli.ParseCli(os.Args)
|
||||||
cmdMissing = cli.ParseCliCommandMissing(err)
|
cmdMissing = cli.ParseCliCommandMissing(err1)
|
||||||
|
|
||||||
// initialisiere basic optionen wie Logging
|
// Programmeinstellungen initialisieren
|
||||||
showChecks = false
|
showChecks = false
|
||||||
if err == nil {
|
if err1 == nil {
|
||||||
if !(arguments.ModeRun.Happened() && arguments.InteractiveMode()) {
|
if !(arguments.ModeRun.Happened() && arguments.InteractiveMode()) {
|
||||||
logging.SetQuietMode(arguments.QuietModeOn())
|
logging.SetQuietMode(arguments.QuietModeOn())
|
||||||
logging.SetDebugMode(arguments.DebugModeOn())
|
logging.SetDebugMode(arguments.DebugModeOn())
|
||||||
@@ -63,34 +65,39 @@ func main() {
|
|||||||
logging.SetAnsiMode(arguments.ShowColour())
|
logging.SetAnsiMode(arguments.ShowColour())
|
||||||
showChecks = arguments.ShowChecks()
|
showChecks = arguments.ShowChecks()
|
||||||
}
|
}
|
||||||
|
err2 = setup.AppConfigInitialise()
|
||||||
// app config (intern) intialisieren
|
|
||||||
err = setup.AppConfigInitialise()
|
|
||||||
setup.SetAppConfigPerformChecks(showChecks)
|
setup.SetAppConfigPerformChecks(showChecks)
|
||||||
|
|
||||||
if err == nil {
|
// Fehler melden (fatal)
|
||||||
if arguments.ModeVersion.Happened() {
|
if err1 != nil && !cmdMissing {
|
||||||
endpoints_print.Version()
|
logging.Fatal(err1)
|
||||||
return
|
}
|
||||||
} else if arguments.ModeRun.Happened() {
|
if err2 != nil {
|
||||||
if arguments.InteractiveMode() {
|
logging.Fatal(err2)
|
||||||
endpoints_run.RunInteractive()
|
}
|
||||||
} else {
|
// Wenn der Artefakt ohne Argument aufgerufen wird, keinen Fehler melden, sondern im it-Modus ausführen
|
||||||
err = endpoints_run.RunNonInteractive(arguments.GetConfigFile())
|
if cmdMissing {
|
||||||
if err != nil {
|
|
||||||
logging.Fatal(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
} else if arguments.ModeHelp.Happened() {
|
|
||||||
endpoints_print.Help()
|
|
||||||
return
|
|
||||||
} else {
|
|
||||||
endpoints_run.RunInteractive()
|
|
||||||
}
|
|
||||||
} else if cmdMissing {
|
|
||||||
endpoints_run.RunInteractive()
|
endpoints_run.RunInteractive()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Sonst Commands behandeln
|
||||||
|
if arguments.ModeHelp.Happened() {
|
||||||
|
endpoints_print.Help()
|
||||||
|
return
|
||||||
|
} else if arguments.ModeVersion.Happened() {
|
||||||
|
endpoints_print.Version()
|
||||||
|
return
|
||||||
|
} else if arguments.ModeRun.Happened() {
|
||||||
|
if arguments.InteractiveMode() {
|
||||||
|
endpoints_run.RunInteractive()
|
||||||
|
} else {
|
||||||
|
err3 = endpoints_run.RunNonInteractive(arguments.GetConfigFile())
|
||||||
|
if err3 != nil {
|
||||||
|
logging.Fatal(err3)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
} else {
|
} else {
|
||||||
logging.Fatal(err)
|
endpoints_run.RunInteractive()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,94 +14,68 @@ import (
|
|||||||
* GLOBAL VARIABLES/CONSTANTS
|
* GLOBAL VARIABLES/CONSTANTS
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
var _output_list [][2]int
|
//
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
* ALGORITHM next greater element
|
* ALGORITHM next greater element
|
||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Inputs: L = Liste von Zahlen, x = Zahl.
|
Inputs: L = Liste von Zahlen.
|
||||||
|
|
||||||
Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element
|
Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element
|
||||||
*/
|
*/
|
||||||
func NextGreaterElement(L []int) [][2]int {
|
func NextGreaterElement(L []int) [][2]int {
|
||||||
clearOutput()
|
output := [][2]int{}
|
||||||
if len(L) == 0 {
|
|
||||||
return output()
|
|
||||||
}
|
|
||||||
|
|
||||||
S := stacks.CREATE()
|
S := stacks.CREATE()
|
||||||
|
S.INIT()
|
||||||
|
|
||||||
for i := 0; i < len(L); i++ {
|
for i := 0; i < len(L); i++ {
|
||||||
logging.Debug("Lies Element L[%v] ein", i)
|
logging.Debug("Stack S | %v", S)
|
||||||
|
logging.Debug("Nächstes List-Element L[%v] = %v betrachten", i, L[i])
|
||||||
nextElement := L[i]
|
nextElement := L[i]
|
||||||
|
|
||||||
logging.Debug("Stack S | %v", S)
|
logging.Debug("Alle top Elemente vom Stack, die < nextElement sind, mit L[i] paaren")
|
||||||
if !S.EMPTY() {
|
// Führe aus, bis top Element >= nextElement oder Stack leer ist.
|
||||||
logging.Debug("Entferne alle top Elemente vom Stack bis >= nextElement")
|
for !S.EMPTY() { // ACHTUNG: schreibe 'while' im Pseudocode, denn dies ist eine while-Schleife in golang
|
||||||
element := S.TOP()
|
element := S.TOP()
|
||||||
S.POP()
|
if element < nextElement {
|
||||||
metrics.AddTimeCost()
|
// falls top Element < next Element, zum Output hinzufügen und vom Stack entfernen
|
||||||
/*
|
logging.Debug("Stack S | %v; top Element < nextElement; ==> pop und Paar zum Output hinzufügen", S)
|
||||||
Entferne kleinere Elemente vom Stack
|
output = append(output, [2]int{element, nextElement})
|
||||||
Aktuelles Element ist jeweils größerer rechter Partner
|
|
||||||
*/
|
|
||||||
for element < nextElement {
|
|
||||||
logging.Debug("Stack S | %v", S)
|
|
||||||
addToOutput(element, nextElement)
|
|
||||||
if S.EMPTY() {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
element = S.TOP()
|
|
||||||
S.POP()
|
S.POP()
|
||||||
metrics.AddTimeCost()
|
metrics.AddMovesCost()
|
||||||
|
logging.Debug("Stack S | %v", S)
|
||||||
|
} else if element > nextElement {
|
||||||
|
// falls top Element > next Element, auf Stack lassen und Schleife abbrechen.
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
// falls top Element == next Element, vom Stack entfernen und Schleife abbrechen.
|
||||||
|
S.POP()
|
||||||
|
metrics.AddMovesCost()
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// lege letztes Element zurück
|
|
||||||
if element > nextElement {
|
|
||||||
logging.Debug("Element >= nextElement zurücklegen")
|
|
||||||
S.PUSH(element)
|
|
||||||
metrics.AddTimeCost()
|
|
||||||
}
|
|
||||||
logging.Debug("Stack S | %v", S)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
S.PUSH(nextElement)
|
|
||||||
metrics.AddTimeCost()
|
|
||||||
logging.Debug("L[%v] auf Stack legen", i)
|
logging.Debug("L[%v] auf Stack legen", i)
|
||||||
logging.Debug("Stack S | %v", S)
|
S.PUSH(nextElement)
|
||||||
|
metrics.AddMovesCost()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logging.Debug("Stack S | %v", S)
|
||||||
|
|
||||||
// was übrig bleibt hat kein größeres Element
|
// was übrig bleibt hat kein größeres Element
|
||||||
logging.Debug("Alles übrige auf Stack hat kein nächstes größeres Element")
|
logging.Debug("Alles übrige auf Stack hat kein nächstes größeres Element")
|
||||||
for !S.EMPTY() {
|
for !S.EMPTY() { // ACHTUNG: schreibe 'while' im Pseudocode, denn dies ist eine while-Schleife in golang
|
||||||
metrics.AddTimeCost()
|
|
||||||
logging.Debug("Stack S | %v", S)
|
logging.Debug("Stack S | %v", S)
|
||||||
element := S.TOP()
|
element := S.TOP()
|
||||||
|
output = append(output, [2]int{element, -1})
|
||||||
S.POP()
|
S.POP()
|
||||||
addToOutput(element, -1)
|
metrics.AddMovesCost()
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.Debug("Stack S | %v", S)
|
logging.Debug("Stack S | %v", S)
|
||||||
|
|
||||||
return output()
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
|
||||||
* AUXILIARY METHODS
|
|
||||||
* ---------------------------------------------------------------- */
|
|
||||||
|
|
||||||
func clearOutput() {
|
|
||||||
_output_list = [][2]int{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func addToOutput(m int, n int) {
|
|
||||||
_output_list = append(_output_list, [2]int{m, n})
|
|
||||||
}
|
|
||||||
|
|
||||||
func output() [][2]int {
|
|
||||||
var output = make([][2]int, len(_output_list))
|
|
||||||
copy(output, _output_list)
|
|
||||||
clearOutput()
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func postChecks(L []int, pairs [][2]int, _ ...interface{}) error {
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func FancyNextGreaterElement(input_L []int) ([][2]int, error) {
|
func FancyNextGreaterElement(input_L []int) ([][2]int, error) {
|
||||||
var name = "Binärsuchalgorithmus"
|
var name = "Next Greater Element"
|
||||||
var inputs = map[string]interface{}{
|
var inputs = map[string]interface{}{
|
||||||
"L": input_L,
|
"L": input_L,
|
||||||
}
|
}
|
||||||
|
|||||||
81
code/golang/pkg/data_structures/queues/queues.go
Normal file
81
code/golang/pkg/data_structures/queues/queues.go
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
package queues
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* IMPORTS
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* GLOBAL VARIABLES/CONSTANTS
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* TYPE
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
type QueueInt struct {
|
||||||
|
values *[]int
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ---------------------------------------------------------------- *
|
||||||
|
* METHODS queues
|
||||||
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
|
func CREATE() QueueInt {
|
||||||
|
return QueueInt{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *QueueInt) INIT() {
|
||||||
|
S.values = &[]int{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S QueueInt) Length() int {
|
||||||
|
if S.values == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return len(*S.values)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S QueueInt) String() string {
|
||||||
|
if S.EMPTY() {
|
||||||
|
return "-"
|
||||||
|
}
|
||||||
|
values := []string{}
|
||||||
|
n := S.Length()
|
||||||
|
for i := n - 1; i >= 0; i-- {
|
||||||
|
value := (*S.values)[i]
|
||||||
|
values = append(values, fmt.Sprintf("%v", value))
|
||||||
|
}
|
||||||
|
return fmt.Sprintf(strings.Join(values, " -> "))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S QueueInt) EMPTY() bool {
|
||||||
|
return S.Length() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *QueueInt) ENQUEUE(x int) {
|
||||||
|
if S.values == nil {
|
||||||
|
panic("Queue not initialised!")
|
||||||
|
}
|
||||||
|
*S.values = append(*S.values, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *QueueInt) FRONT() int {
|
||||||
|
if S.EMPTY() {
|
||||||
|
panic("Cannot read from empty queue!")
|
||||||
|
}
|
||||||
|
return (*S.values)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *QueueInt) DEQUEUE() {
|
||||||
|
if S.EMPTY() {
|
||||||
|
panic("Cannot remove from empty queue!")
|
||||||
|
}
|
||||||
|
*S.values = (*S.values)[1:]
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ import (
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
type StackInt struct {
|
type StackInt struct {
|
||||||
values []int
|
values *[]int
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- *
|
/* ---------------------------------------------------------------- *
|
||||||
@@ -28,45 +28,54 @@ type StackInt struct {
|
|||||||
* ---------------------------------------------------------------- */
|
* ---------------------------------------------------------------- */
|
||||||
|
|
||||||
func CREATE() StackInt {
|
func CREATE() StackInt {
|
||||||
return StackInt{
|
return StackInt{}
|
||||||
values: []int{},
|
}
|
||||||
|
|
||||||
|
func (S *StackInt) INIT() {
|
||||||
|
S.values = &[]int{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S StackInt) Length() int {
|
||||||
|
if S.values == nil {
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
}
|
return len(*S.values)
|
||||||
|
|
||||||
func (S *StackInt) INIT() StackInt {
|
|
||||||
return StackInt{
|
|
||||||
values: []int{},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (S StackInt) EMPTY() bool {
|
|
||||||
return len(S.values) == 0
|
|
||||||
}
|
|
||||||
|
|
||||||
func (S *StackInt) PUSH(x int) {
|
|
||||||
S.values = append(S.values, x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (S *StackInt) TOP() int {
|
|
||||||
if S.EMPTY() {
|
|
||||||
panic("Cannot pop from empty stack!")
|
|
||||||
}
|
|
||||||
return S.values[len(S.values)-1]
|
|
||||||
}
|
|
||||||
|
|
||||||
func (S *StackInt) POP() int {
|
|
||||||
x := S.TOP()
|
|
||||||
S.values = S.values[:(len(S.values) - 1)]
|
|
||||||
return x
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (S StackInt) String() string {
|
func (S StackInt) String() string {
|
||||||
if len(S.values) == 0 {
|
if S.EMPTY() {
|
||||||
return "-"
|
return "-"
|
||||||
}
|
}
|
||||||
values := []string{}
|
values := []string{}
|
||||||
for _, value := range S.values {
|
for _, value := range *S.values {
|
||||||
values = append(values, fmt.Sprintf("%v", value))
|
values = append(values, fmt.Sprintf("%v", value))
|
||||||
}
|
}
|
||||||
return fmt.Sprintf(strings.Join(values, ", "))
|
return fmt.Sprintf(strings.Join(values, ", "))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (S StackInt) EMPTY() bool {
|
||||||
|
return S.Length() == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *StackInt) PUSH(x int) {
|
||||||
|
if S.values == nil {
|
||||||
|
panic("Stack not initialised!")
|
||||||
|
}
|
||||||
|
*S.values = append(*S.values, x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *StackInt) TOP() int {
|
||||||
|
if S.EMPTY() {
|
||||||
|
panic("Cannot read from empty stack!")
|
||||||
|
}
|
||||||
|
n := S.Length()
|
||||||
|
return (*S.values)[n-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (S *StackInt) POP() {
|
||||||
|
if S.EMPTY() {
|
||||||
|
panic("Cannot remove from empty stack!")
|
||||||
|
}
|
||||||
|
n := S.Length()
|
||||||
|
*S.values = (*S.values)[:(n - 1)]
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# LOCAL ARGUMENTS
|
# LOCAL ARGUMENTS
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
PATH_TO_CONFIG:=../config.yml
|
PATH_TO_CONFIG:=../config.yml#<- kann durch Pfad zur eigenen yml-Datei ersetzt werden
|
||||||
COLOUR:=true# <- auf false stellen, falls es Probleme gibt
|
COLOUR:=true
|
||||||
|
PYTHON:=python3
|
||||||
|
PIP:=python3 -m pip
|
||||||
|
|
||||||
|
## für Windows weichen Defaultsettings leicht ab:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
PYTHON:=py -3
|
COLOUR:=false# <- man kann als 'true' setzen, aber in Windows funktioniert es möglicherweise nicht
|
||||||
PIP:=py -3 -m pip
|
PYTHON:=py -3
|
||||||
else
|
PIP:=py -3 -m pip
|
||||||
PYTHON:=python3
|
|
||||||
PIP:=python3 -m pip
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
X.Y.Z
|
0.0.0
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import sys;
|
|||||||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.abspath(__file__), '..')));
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.abspath(__file__), '..')));
|
||||||
|
|
||||||
from src.setup.cli import *;
|
from src.setup.cli import *;
|
||||||
|
from src.endpoints.exports import *;
|
||||||
from src.main import enter;
|
from src.main import enter;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -24,10 +25,18 @@ from src.main import enter;
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sys.tracebacklimit = 0;
|
|
||||||
sys.tracebacklimit = 0;
|
sys.tracebacklimit = 0;
|
||||||
try:
|
try:
|
||||||
args = GetArgumentsFromCli(sys.argv[1:]);
|
args = GetArgumentsFromCli(*sys.argv[1:]);
|
||||||
except:
|
except:
|
||||||
|
endpoint_help();
|
||||||
exit(1);
|
exit(1);
|
||||||
enter(quiet=args.quiet, debug=args.debug, mode=args.mode[0], path=args.path);
|
enter(
|
||||||
|
mode=args.mode,
|
||||||
|
it=args.it,
|
||||||
|
quiet=args.quiet,
|
||||||
|
debug=args.debug,
|
||||||
|
checks=args.checks,
|
||||||
|
colour=args.colour,
|
||||||
|
config=args.config,
|
||||||
|
);
|
||||||
|
|||||||
@@ -6,4 +6,5 @@
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
from src.algorithms.search.exports import *;
|
from src.algorithms.search.exports import *;
|
||||||
|
from src.algorithms.stacks.exports import *;
|
||||||
from src.algorithms.sum.exports import *;
|
from src.algorithms.sum.exports import *;
|
||||||
|
|||||||
0
code/python/src/algorithms/stacks/__init__.py
Normal file
0
code/python/src/algorithms/stacks/__init__.py
Normal file
8
code/python/src/algorithms/stacks/exports.py
Normal file
8
code/python/src/algorithms/stacks/exports.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# EXPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from src.algorithms.stacks.next_greater_element import NextGreaterElement;
|
||||||
91
code/python/src/algorithms/stacks/next_greater_element.py
Normal file
91
code/python/src/algorithms/stacks/next_greater_element.py
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from src.local.typing import *;
|
||||||
|
|
||||||
|
from src.core.log import *;
|
||||||
|
from src.core.metrics import *;
|
||||||
|
from src.data_structures.stacks import Stack;
|
||||||
|
from src.algorithms.methods import *;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# GLOBAL VARIABLES/CONSTANTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# CHECKS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def preChecks(L: List[int], **_):
|
||||||
|
# TODO
|
||||||
|
return;
|
||||||
|
|
||||||
|
def postChecks(L: List[int], **_):
|
||||||
|
# TODO
|
||||||
|
return;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# ALGORITHM next greater element
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
@algorithmInfos(name='NextGreaterElement (with stacks)', outputnames=['pairs'], preChecks=preChecks, postChecks=postChecks)
|
||||||
|
def NextGreaterElement(L: List[int]) -> List[Tuple[int,int]]:
|
||||||
|
'''
|
||||||
|
Inputs: L = Liste von Zahlen.
|
||||||
|
Outputs: Liste von Paaren von Elementen und ihrem nächsten größeren Element
|
||||||
|
'''
|
||||||
|
output = [];
|
||||||
|
|
||||||
|
S = Stack();
|
||||||
|
S.INIT();
|
||||||
|
|
||||||
|
for i in range(len(L)):
|
||||||
|
logDebug('Stack S | {S}'.format(S=S));
|
||||||
|
logDebug('Nächstes List-Element L[{i}] = {el} betrachten'.format(i=i, el=L[i]));
|
||||||
|
nextElement = L[i];
|
||||||
|
|
||||||
|
logDebug('Alle top Elemente vom Stack, die < nextElement sind, mit L[i] paaren');
|
||||||
|
# Führe aus, bis top Element >= nextElement oder Stack leer ist.
|
||||||
|
logDebug('Stack S | {S}'.format(S=S));
|
||||||
|
while not S.EMPTY():
|
||||||
|
element = S.TOP();
|
||||||
|
# falls element < next Element, zum Output hinzufügen und vom Stack entfernen
|
||||||
|
if element < nextElement:
|
||||||
|
logDebug('Stack S | {S}; top Element < nextElement; ==> pop und Paar zum Output hinzufügen'.format(S=S))
|
||||||
|
output.append((element, nextElement));
|
||||||
|
S.POP();
|
||||||
|
AddMovesCost();
|
||||||
|
logDebug('Stack S | {S}'.format(S=S));
|
||||||
|
# falls top Element > next Element, auf Stack lassen und Schleife abbrechen.
|
||||||
|
elif element > nextElement:
|
||||||
|
break
|
||||||
|
# falls top Element == next Element, vom Stack entfernen und Schleife abbrechen.
|
||||||
|
else:
|
||||||
|
S.POP()
|
||||||
|
AddMovesCost()
|
||||||
|
break
|
||||||
|
logDebug('Stack S | {S}'.format(S=S));
|
||||||
|
|
||||||
|
logDebug('L[{i}] auf Stack legen'.format(i=i));
|
||||||
|
S.PUSH(nextElement);
|
||||||
|
AddMovesCost();
|
||||||
|
|
||||||
|
logDebug('Stack S | {S}'.format(S=S));
|
||||||
|
|
||||||
|
# was übrig bleibt hat kein größeres Element
|
||||||
|
logDebug('Alles übrige auf Stack hat kein nächstes größeres Element')
|
||||||
|
while not S.EMPTY():
|
||||||
|
logDebug('Stack S | {S}'.format(S=S));
|
||||||
|
element = S.TOP();
|
||||||
|
S.POP();
|
||||||
|
AddMovesCost();
|
||||||
|
output.append((element, -1));
|
||||||
|
|
||||||
|
logDebug('Stack S | {S}'.format(S=S))
|
||||||
|
return output;
|
||||||
@@ -22,24 +22,20 @@ _tmr = None;
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
class Counter(object):
|
class Counter(object):
|
||||||
_nr_steps: int;
|
value: int;
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.reset();
|
self.reset();
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return str(self._nr_steps);
|
return str(self.value);
|
||||||
|
|
||||||
@property
|
|
||||||
def numberOfStep(self) -> int:
|
|
||||||
return self._nr_steps;
|
|
||||||
|
|
||||||
def add(self, n: int = 1):
|
def add(self, n: int = 1):
|
||||||
self._nr_steps += n;
|
self.value += n;
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
self._nr_steps = 0;
|
self.value = 0;
|
||||||
return self;
|
return self;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -86,6 +82,7 @@ class Timer(object):
|
|||||||
|
|
||||||
## Initialisierung:
|
## Initialisierung:
|
||||||
_ctr_time = Counter();
|
_ctr_time = Counter();
|
||||||
|
_ctr_moves = Counter();
|
||||||
_ctr_space = Counter();
|
_ctr_space = Counter();
|
||||||
_tmr = Timer();
|
_tmr = Timer();
|
||||||
|
|
||||||
@@ -95,10 +92,12 @@ _tmr = Timer();
|
|||||||
|
|
||||||
def ResetMetrics():
|
def ResetMetrics():
|
||||||
global _ctr_time;
|
global _ctr_time;
|
||||||
|
global _ctr_moves;
|
||||||
global _ctr_space;
|
global _ctr_space;
|
||||||
global _tmr;
|
global _tmr;
|
||||||
|
|
||||||
_ctr_time.reset();
|
_ctr_time.reset();
|
||||||
|
_ctr_moves.reset();
|
||||||
_ctr_space.reset();
|
_ctr_space.reset();
|
||||||
_tmr.reset();
|
_tmr.reset();
|
||||||
return;
|
return;
|
||||||
@@ -116,16 +115,29 @@ def AddTimeCost(n: int = 1):
|
|||||||
_ctr_time.add(n);
|
_ctr_time.add(n);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
def AddMovesCost(n: int = 1):
|
||||||
|
global _ctr_moves;
|
||||||
|
_ctr_moves.add(n);
|
||||||
|
return;
|
||||||
|
|
||||||
def AddSpaceCost(n: int = 1):
|
def AddSpaceCost(n: int = 1):
|
||||||
global _ctr_space;
|
global _ctr_space;
|
||||||
_ctr_space.add(n);
|
_ctr_space.add(n);
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
def SetSpaceCost(n: int):
|
||||||
|
global _ctr_space;
|
||||||
|
_ctr_space.value = n;
|
||||||
|
return;
|
||||||
|
|
||||||
def GetTimeCost() -> int:
|
def GetTimeCost() -> int:
|
||||||
return _ctr_time.numberOfStep;
|
return _ctr_time.value;
|
||||||
|
|
||||||
|
def GetMovesCost() -> int:
|
||||||
|
return _ctr_moves.value;
|
||||||
|
|
||||||
def GetSpaceCost() -> int:
|
def GetSpaceCost() -> int:
|
||||||
return _ctr_space.numberOfStep;
|
return _ctr_space.value;
|
||||||
|
|
||||||
def GetTimeElapsed() -> timedelta:
|
def GetTimeElapsed() -> timedelta:
|
||||||
global _tmr;
|
global _tmr;
|
||||||
|
|||||||
0
code/python/src/data_structures/__init__.py
Normal file
0
code/python/src/data_structures/__init__.py
Normal file
52
code/python/src/data_structures/queues.py
Normal file
52
code/python/src/data_structures/queues.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from local.typing import *;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# GLOBAL VARIABLES/CONSTANTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# CLASS Queue
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
class Queue(object):
|
||||||
|
_initialised: bool;
|
||||||
|
values: List[int];
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._initialised = False;
|
||||||
|
|
||||||
|
def INIT(self):
|
||||||
|
self.values = [];
|
||||||
|
self._initialised = True;
|
||||||
|
|
||||||
|
def EMPTY(self) -> bool:
|
||||||
|
return not self._initialised or len(self.values) == 0;
|
||||||
|
|
||||||
|
def ENQUEUE(self, x: int):
|
||||||
|
if not self._initialised:
|
||||||
|
raise Exception('Queue not initialised!')
|
||||||
|
self.values.append(x);
|
||||||
|
|
||||||
|
def FRONT(self) -> int:
|
||||||
|
if self.EMPTY():
|
||||||
|
raise Exception('Cannot read from empty queue!')
|
||||||
|
return self.values[0];
|
||||||
|
|
||||||
|
def DEQUEUE(self) -> int:
|
||||||
|
if self.EMPTY():
|
||||||
|
raise Exception('Cannot remove from empty queue!')
|
||||||
|
self.values = self.values[1:];
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
if len(self.values) == 0:
|
||||||
|
return '-';
|
||||||
|
return ', '.join([str(x) for x in self.values]);
|
||||||
52
code/python/src/data_structures/stacks.py
Normal file
52
code/python/src/data_structures/stacks.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from local.typing import *;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# GLOBAL VARIABLES/CONSTANTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
#
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# CLASS Stack
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
class Stack(object):
|
||||||
|
_initialised: bool;
|
||||||
|
values: List[int];
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._initialised = False;
|
||||||
|
|
||||||
|
def INIT(self):
|
||||||
|
self.values = [];
|
||||||
|
self._initialised = True;
|
||||||
|
|
||||||
|
def EMPTY(self) -> bool:
|
||||||
|
return not self._initialised or len(self.values) == 0;
|
||||||
|
|
||||||
|
def PUSH(self, x: int):
|
||||||
|
if not self._initialised:
|
||||||
|
raise Exception('Stack not initialised!');
|
||||||
|
self.values.append(x);
|
||||||
|
|
||||||
|
def TOP(self) -> int:
|
||||||
|
if self.EMPTY():
|
||||||
|
raise Exception('Cannot read from empty stack!');
|
||||||
|
return self.values[-1];
|
||||||
|
|
||||||
|
def POP(self) -> int:
|
||||||
|
if self.EMPTY():
|
||||||
|
raise Exception('Cannot remove from empty stack!');
|
||||||
|
self.values = self.values[:-1];
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
if len(self.values) == 0:
|
||||||
|
return '-';
|
||||||
|
return ', '.join([str(x) for x in self.values]);
|
||||||
@@ -6,17 +6,14 @@
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
from src.core.log import *;
|
from src.core.log import *;
|
||||||
from src.setup.cli import GetArgumentsFromCli;
|
from src.setup import assets;
|
||||||
from src.setup.cli import GetArgumentParser;
|
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# ENDPOINT version
|
# ENDPOINT version
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
def version():
|
def version():
|
||||||
with open('assets/VERSION', 'r') as fp:
|
logPlain(assets.Version());
|
||||||
version = ('\n'.join(fp.readlines())).strip();
|
|
||||||
logPlain(version);
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -24,6 +21,5 @@ def version():
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
def help():
|
def help():
|
||||||
parser = GetArgumentParser();
|
logPlain(assets.Help());
|
||||||
parser.print_help();
|
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
from src.core.log import *;
|
from src.core.log import *;
|
||||||
from src.core.config import *;
|
from src.core.config import *;
|
||||||
from src.setup.display import *;
|
from src.setup.display import *;
|
||||||
|
from src.setup import assets;
|
||||||
from src.algorithms.exports import *;
|
from src.algorithms.exports import *;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -18,6 +19,7 @@ def runInteractive():
|
|||||||
'''
|
'''
|
||||||
Startet Programm im interaktiven Modus (Konsole).
|
Startet Programm im interaktiven Modus (Konsole).
|
||||||
'''
|
'''
|
||||||
|
logPlain(assets.Logo());
|
||||||
logWarn('Interaktiver Modus noch nicht implementiert.');
|
logWarn('Interaktiver Modus noch nicht implementiert.');
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -31,6 +33,7 @@ def runNonInteractive(path: str):
|
|||||||
'''
|
'''
|
||||||
config = ReadConfigFile(path);
|
config = ReadConfigFile(path);
|
||||||
cases = GetAttribute(config, 'parts', 'cases', expectedtype=list, default=[]);
|
cases = GetAttribute(config, 'parts', 'cases', expectedtype=list, default=[]);
|
||||||
|
logPlain(assets.Logo());
|
||||||
for caseindex, case in enumerate(cases):
|
for caseindex, case in enumerate(cases):
|
||||||
command = GetAttribute(case, 'command', expectedtype=str, default='');
|
command = GetAttribute(case, 'command', expectedtype=str, default='');
|
||||||
descr = GetAttribute(case, 'description', expectedtype=str, default='');
|
descr = GetAttribute(case, 'description', expectedtype=str, default='');
|
||||||
@@ -39,11 +42,7 @@ def runNonInteractive(path: str):
|
|||||||
DisplayStartOfCase(caseindex, descr);
|
DisplayStartOfCase(caseindex, descr);
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if command == 'algorithm-sum-maxsub':
|
if command == 'algorithm-search-sequential':
|
||||||
MaxSubSum(L=inputs['L']);
|
|
||||||
elif command == 'algorithm-sum-maxsub-dc':
|
|
||||||
MaxSubSumDC(L=inputs['L']);
|
|
||||||
elif command == 'algorithm-search-sequential':
|
|
||||||
SequentialSearch(L=inputs['L'], x=inputs['x']);
|
SequentialSearch(L=inputs['L'], x=inputs['x']);
|
||||||
elif command == 'algorithm-search-binary':
|
elif command == 'algorithm-search-binary':
|
||||||
BinarySearch(L=inputs['L'], x=inputs['x']);
|
BinarySearch(L=inputs['L'], x=inputs['x']);
|
||||||
@@ -61,6 +60,12 @@ def runNonInteractive(path: str):
|
|||||||
FindPoison(L=inputs['L']);
|
FindPoison(L=inputs['L']);
|
||||||
elif command == 'algorithm-search-poison-fast':
|
elif command == 'algorithm-search-poison-fast':
|
||||||
FindPoisonFast(L=inputs['L']);
|
FindPoisonFast(L=inputs['L']);
|
||||||
|
elif command == 'algorithm-stacks-next-greater-element':
|
||||||
|
NextGreaterElement(L=inputs['L']);
|
||||||
|
elif command == 'algorithm-sum-maxsub':
|
||||||
|
MaxSubSum(L=inputs['L']);
|
||||||
|
elif command == 'algorithm-sum-maxsub-dc':
|
||||||
|
MaxSubSumDC(L=inputs['L']);
|
||||||
else:
|
else:
|
||||||
raise ValueError('Command \033[1m{}\033[0m nicht erkannt'.format(command));
|
raise ValueError('Command \033[1m{}\033[0m nicht erkannt'.format(command));
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
@@ -13,8 +13,6 @@ sys.path.insert(0, _path_to_python_project);
|
|||||||
os.chdir(_path_to_python_project);
|
os.chdir(_path_to_python_project);
|
||||||
|
|
||||||
from src.core.log import *;
|
from src.core.log import *;
|
||||||
from src.core.utils import IsTrue;
|
|
||||||
from src.core.utils import IsFalse;
|
|
||||||
from src.setup.cli import *;
|
from src.setup.cli import *;
|
||||||
from src.setup import appconfig;
|
from src.setup import appconfig;
|
||||||
from src.endpoints.exports import *;
|
from src.endpoints.exports import *;
|
||||||
@@ -30,14 +28,16 @@ PATH_TO_CONFIG: str = '../config.yml';
|
|||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
def enter(
|
def enter(
|
||||||
mode: str,
|
mode: Union[str, None],
|
||||||
it: bool,
|
it: bool,
|
||||||
quiet: bool,
|
quiet: bool,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
checks: bool,
|
checks: bool,
|
||||||
colour: bool,
|
colour: bool,
|
||||||
config: Any, **_
|
config: Union[str, None],
|
||||||
|
**_
|
||||||
):
|
):
|
||||||
|
# Programmeinstellungen initialisieren
|
||||||
if not (mode == 'run' and it):
|
if not (mode == 'run' and it):
|
||||||
SetQuietMode(quiet);
|
SetQuietMode(quiet);
|
||||||
SetDebugMode(debug);
|
SetDebugMode(debug);
|
||||||
@@ -46,7 +46,15 @@ def enter(
|
|||||||
|
|
||||||
config = config if isinstance(config, str) else PATH_TO_CONFIG;
|
config = config if isinstance(config, str) else PATH_TO_CONFIG;
|
||||||
|
|
||||||
if mode == 'version':
|
# Wenn der Artefakt ohne Argument aufgerufen wird, keinen Fehler melden, sondern im it-Modus ausführen
|
||||||
|
if mode is None:
|
||||||
|
endpoint_runInteractive();
|
||||||
|
return;
|
||||||
|
# Sonst Commands behandeln
|
||||||
|
if mode == 'help':
|
||||||
|
endpoint_help();
|
||||||
|
return;
|
||||||
|
elif mode == 'version':
|
||||||
endpoint_version();
|
endpoint_version();
|
||||||
return;
|
return;
|
||||||
elif mode == 'run':
|
elif mode == 'run':
|
||||||
@@ -54,8 +62,9 @@ def enter(
|
|||||||
endpoint_runInteractive();
|
endpoint_runInteractive();
|
||||||
else:
|
else:
|
||||||
endpoint_runNonInteractive(path=config);
|
endpoint_runNonInteractive(path=config);
|
||||||
else: # elif mode
|
return;
|
||||||
endpoint_help();
|
else:
|
||||||
|
endpoint_runInteractive();
|
||||||
return;
|
return;
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -71,11 +80,11 @@ if __name__ == '__main__':
|
|||||||
endpoint_help();
|
endpoint_help();
|
||||||
exit(1);
|
exit(1);
|
||||||
enter(
|
enter(
|
||||||
mode=args.mode[0],
|
mode=args.mode,
|
||||||
it=args.it,
|
it=args.it,
|
||||||
quiet=args.quiet,
|
quiet=args.quiet,
|
||||||
debug=args.debug,
|
debug=args.debug,
|
||||||
checks=IsTrue(args.checks[0]),
|
checks=args.checks,
|
||||||
colour=IsTrue(args.colour[0]),
|
colour=args.colour,
|
||||||
config=args.config,
|
config=args.config,
|
||||||
);
|
);
|
||||||
|
|||||||
38
code/python/src/setup/assets.py
Normal file
38
code/python/src/setup/assets.py
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# IMPORTS
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
from src.local.io import *;
|
||||||
|
|
||||||
|
from src.core.utils import DedentIgnoreFirstLast
|
||||||
|
from src.setup.cli import GetArgumentParser;
|
||||||
|
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
# METHODS assets
|
||||||
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
def Help() -> str:
|
||||||
|
parser = GetArgumentParser();
|
||||||
|
with io.StringIO() as fp:
|
||||||
|
parser.print_help(fp)
|
||||||
|
text = fp.getvalue();
|
||||||
|
return text;
|
||||||
|
|
||||||
|
def Logo() -> str:
|
||||||
|
## NOTE: expandiert ansi nicht:
|
||||||
|
# with open('assets/LOGO', 'r') as fp:
|
||||||
|
# logo = (''.join(fp.readlines())).strip();
|
||||||
|
logo = DedentIgnoreFirstLast('''
|
||||||
|
+--------------------+
|
||||||
|
| \033[32;1mAlgoDat I\033[0m |
|
||||||
|
+--------------------+
|
||||||
|
''') + '\n';
|
||||||
|
return logo;
|
||||||
|
|
||||||
|
def Version() -> str:
|
||||||
|
with open('assets/VERSION', 'r') as fp:
|
||||||
|
version = (''.join(fp.readlines())).strip();
|
||||||
|
return version;
|
||||||
@@ -10,6 +10,8 @@ from src.local.typing import *;
|
|||||||
|
|
||||||
from src.core.log import *;
|
from src.core.log import *;
|
||||||
from src.core.utils import DedentIgnoreFirstLast;
|
from src.core.utils import DedentIgnoreFirstLast;
|
||||||
|
from src.core.utils import IsTrue;
|
||||||
|
from src.core.utils import IsFalse;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
# GLOBAL VARIABLES
|
# GLOBAL VARIABLES
|
||||||
@@ -28,12 +30,12 @@ def GetArgumentParser() -> argparse.ArgumentParser:
|
|||||||
prog='code/main.py',
|
prog='code/main.py',
|
||||||
description=DedentIgnoreFirstLast('''
|
description=DedentIgnoreFirstLast('''
|
||||||
\033[93;1mBeschreibung:\033[0m
|
\033[93;1mBeschreibung:\033[0m
|
||||||
\033[93;2mEin Programm, das verschiedene Algorithmen aus dem Kurs AlgoDat I testet.\033[0m
|
\033[93;2mEin Programm zur Ausführung verschiedener Algorithmen aus dem Kurs AlgoDat I.\033[0m
|
||||||
'''),
|
'''),
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
);
|
);
|
||||||
parser.add_argument('mode',
|
parser.add_argument('mode',
|
||||||
nargs=1,
|
nargs='?',
|
||||||
choices=['version', 'help', 'run'],
|
choices=['version', 'help', 'run'],
|
||||||
help=DedentIgnoreFirstLast('''
|
help=DedentIgnoreFirstLast('''
|
||||||
help = Hilfsanleitung anzeigen.
|
help = Hilfsanleitung anzeigen.
|
||||||
@@ -51,9 +53,12 @@ def GetArgumentParser() -> argparse.ArgumentParser:
|
|||||||
'''),
|
'''),
|
||||||
),
|
),
|
||||||
parser.add_argument('--colour', nargs=1, type=str, default=['False'], help='(bool) Ob Logging färblich angezeigt wird.')
|
parser.add_argument('--colour', nargs=1, type=str, default=['False'], help='(bool) Ob Logging färblich angezeigt wird.')
|
||||||
parser.add_argument('--config', nargs=1, type=str, help='(string) Pfad zur Configdatei (nur für run Endpunkt).');
|
parser.add_argument('--config', nargs=1, type=str, help='(string) Pfad zur Configdatei (nur für run Endpunkt).');
|
||||||
return parser;
|
return parser;
|
||||||
|
|
||||||
def GetArgumentsFromCli(*cli_args: str) -> argparse.Namespace:
|
def GetArgumentsFromCli(*cli_args: str) -> argparse.Namespace:
|
||||||
parser = GetArgumentParser();
|
parser = GetArgumentParser();
|
||||||
return parser.parse_args(cli_args);
|
args = parser.parse_args(cli_args);
|
||||||
|
args.checks=IsTrue(args.checks[0]);
|
||||||
|
args.colour=IsTrue(args.colour[0]);
|
||||||
|
return args;
|
||||||
|
|||||||
@@ -69,8 +69,9 @@ def DisplayEndOfAlgorithm(*_: Any, **outputs: Any):
|
|||||||
|
|
||||||
def DisplayMetrics():
|
def DisplayMetrics():
|
||||||
logPlain('Dauer der Ausführung: t = \033[1m{}\033[0m'.format(GetTimeElapsed()));
|
logPlain('Dauer der Ausführung: t = \033[1m{}\033[0m'.format(GetTimeElapsed()));
|
||||||
logPlain('Kosten (Zeit): T(n) = \033[1m{}\033[0m'.format(GetTimeCost()));
|
logPlain('Kosten (Zeit): T(n) = \033[1m{}\033[0m'.format(displayCost(GetTimeCost())));
|
||||||
logPlain('Kosten (Platz): S(n) = \033[1m{}\033[0m'.format(GetSpaceCost()));
|
logPlain('Kosten (#Züge): M(n) = \033[1m{}\033[0m'.format(displayCost(GetMovesCost())));
|
||||||
|
logPlain('Kosten (Platz): S(n) = \033[1m{}\033[0m'.format(displayCost(GetSpaceCost())));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
@@ -80,3 +81,6 @@ def DisplayMetrics():
|
|||||||
def DisplayBar(n: int = 80):
|
def DisplayBar(n: int = 80):
|
||||||
logPlain('+{}+'.format('-'*n));
|
logPlain('+{}+'.format('-'*n));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
def displayCost(cost: int) -> str:
|
||||||
|
return str(cost) if cost > 0 else '-';
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ Inhaltsverzeichnis
|
|||||||
- [Vorlesungswoche 2](./woche2.md)
|
- [Vorlesungswoche 2](./woche2.md)
|
||||||
- [Vorlesungswoche 3](./woche3.md)
|
- [Vorlesungswoche 3](./woche3.md)
|
||||||
- [Vorlesungswoche 4](./woche4.md)
|
- [Vorlesungswoche 4](./woche4.md)
|
||||||
- [Vorlesungswoche 5](./woche4.md)
|
- [Vorlesungswoche 5](./woche5.md)
|
||||||
- [Vorlesungswoche 6](./woche4.md)
|
- [Vorlesungswoche 6](./woche6.md)
|
||||||
- [Vorlesungswoche 7](./woche4.md)
|
- [Vorlesungswoche 7](./woche7.md)
|
||||||
- [Vorlesungswoche 8](./woche4.md)
|
- [Vorlesungswoche 8](./woche8.md)
|
||||||
- [Vorlesungswoche 9](./woche4.md)
|
- [Vorlesungswoche 9](./woche9.md)
|
||||||
- [Vorlesungswoche 10](./woche10.md)
|
- [Vorlesungswoche 10](./woche10.md)
|
||||||
- [Vorlesungswoche 11](./woche11.md)
|
- [Vorlesungswoche 11](./woche11.md)
|
||||||
- [Vorlesungswoche 12](./woche12.md)
|
- [Vorlesungswoche 12](./woche12.md)
|
||||||
|
|||||||
@@ -2,13 +2,26 @@
|
|||||||
|
|
||||||
## Agenda ##
|
## Agenda ##
|
||||||
|
|
||||||
- [ ]
|
- Gruppe 1:
|
||||||
- [ ]
|
- Verkettete Listen
|
||||||
|
- basic methods/attributes
|
||||||
|
- Stacks + Queues
|
||||||
|
- LIFO=FILO vs. FIFO=LILO
|
||||||
|
- PseudoCode-Algorithmus für NextGreaterElement mittels Stacks erarbeitet und diskutiert
|
||||||
|
- ACHTUNG: im code-Ordner ([go-Variante](../code/golang/pkg/algorithms/stacks/next_greater_element/next_greater_element.go) und [python-Variante](../code/python/src/algorithms/stacks/next_greater_element.py)) habe ich einen vereinfachten Algorithmus implementiert.
|
||||||
|
- Gruppe 2:
|
||||||
|
- PseudoCode-Algorithmus für NextGreaterElement mittels Stacks erarbeitet und diskutiert
|
||||||
|
- ACHTUNG: im code-Ordner ([go-Variante](../code/golang/pkg/algorithms/stacks/next_greater_element/next_greater_element.go) und [python-Variante](../code/python/src/algorithms/stacks/next_greater_element.py)) habe ich einen vereinfachten Algorithmus implementiert.
|
||||||
|
- Grundkonzepte für gerichtete/ungerichtete Graphen und Bäume besprochen
|
||||||
|
|
||||||
## Nächste Woche ##
|
## Nächste Woche ##
|
||||||
|
|
||||||
-
|
- Sortierungsalgorithmen
|
||||||
|
- Bäume
|
||||||
|
|
||||||
### TODOs (Studierende) ###
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
-
|
- VL-Inhalte aus Wochen 3 + 4 durchgehen
|
||||||
|
- jeden Sortierungsalgorithmus und MaxHeap verstehen
|
||||||
|
- Darstellung von Daten als Bäume verstehen
|
||||||
|
- freiwillige ÜB 4 + Pflichtserie 2
|
||||||
|
|||||||
@@ -2,13 +2,41 @@
|
|||||||
|
|
||||||
## Agenda ##
|
## Agenda ##
|
||||||
|
|
||||||
- [ ]
|
- Gruppe 1
|
||||||
- [ ]
|
- [x] Alle Sortierverfahren durchgegangen; argumentierte, wieso die Algorithmen korrekt sind.
|
||||||
|
- [x] Bäume und Listendarstellung von **fast vollständige binäre Bäume**.
|
||||||
|
- [x] Max-Heap-Eigenschaft (MHE).
|
||||||
|
- [x] Theorem: folgende Aussagen sind äquivalent
|
||||||
|
- T hat MHE
|
||||||
|
- (Definition) alle Unterbäume von T haben Max in Wurzel, d. h.
|
||||||
|
für alle Knoten, e, gilt
|
||||||
|
```
|
||||||
|
value(e) ≥ max{value(e') | e' Unterhalb von e in T}
|
||||||
|
```
|
||||||
|
- für alle Knoten, e, gilt
|
||||||
|
```
|
||||||
|
value(e) ≥ max{value(e') | e' Tochterknoten von e in T}
|
||||||
|
```
|
||||||
|
- L[i] = L[2i+1] und L[i] = L[2i+2] (jeweils solange Indexes in Listendarstellung L, wobei L = Listendarstellung von Baum T).
|
||||||
|
- Gruppe 2
|
||||||
|
- [x] Alle Sortierverfahren durchgegangen; argumentierte, wieso die Algorithmen korrekt sind.
|
||||||
|
(Etwas ausführlicher, weil MHE, usw. schon in der Übung diskutiert wurden.)
|
||||||
|
|
||||||
|
**Anmerkung.**
|
||||||
|
Bei Quicksort konnten wir sehen, dass die Zeit- (und Satzbewegungs!) komplexität durch
|
||||||
|
$C(n) = 2C(n/2) + Θ(n)$ gegeben ist (warum diese Koeffizienten, warum Θ(n)?).
|
||||||
|
</br>
|
||||||
|
Laut **Mastertheorem** gilt also $C(n) ∈ Θ(n·log(n))$ (warum?).
|
||||||
|
</br>
|
||||||
|
Das ist aber der Worst-case.
|
||||||
|
</br>
|
||||||
|
Wie verhält sich das beim Average-Case ($C_{av}(n)$)?
|
||||||
|
|
||||||
## Nächste Woche ##
|
## Nächste Woche ##
|
||||||
|
|
||||||
-
|
- Ab VL5 + Blatt 6.
|
||||||
|
|
||||||
### TODOs (Studierende) ###
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
-
|
- VL-Inhalte aus Wochen 4 + 5 durchgehen
|
||||||
|
- freiwillige ÜB 5 + Pflichtserie 3.
|
||||||
|
|||||||
@@ -2,13 +2,10 @@
|
|||||||
|
|
||||||
## Agenda ##
|
## Agenda ##
|
||||||
|
|
||||||
- [ ]
|
- [x] Mergesort, inkl. Pseudo-Code
|
||||||
- [ ]
|
- [x] natürliches Mergesort, inkl. Aspekte
|
||||||
|
- [x] k-Wege Mergesort
|
||||||
## Nächste Woche ##
|
|
||||||
|
|
||||||
-
|
|
||||||
|
|
||||||
### TODOs (Studierende) ###
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
-
|
- weiter an Pflichtserie3 arbeiten.
|
||||||
|
|||||||
@@ -2,13 +2,19 @@
|
|||||||
|
|
||||||
## Agenda ##
|
## Agenda ##
|
||||||
|
|
||||||
- [ ]
|
- [x] Orga: nochmalige Abstimmung der Studierenden über Präsenz v. Digital
|
||||||
- [ ]
|
---> überwiegende Mehrheit für weiteren Präsenzbetrieb.
|
||||||
|
|
||||||
## Nächste Woche ##
|
Aspekte und Berechnungen mit binären Suchbäumen
|
||||||
|
|
||||||
-
|
- Aspekte, insbesondere *ausgeglichen*.
|
||||||
|
- Motivation: wieso wollen wir *ausgeglichene* Suchbäume?
|
||||||
|
- Optimierung der Tiefe h vis-á-vis Anzahl der Knoten, n.
|
||||||
|
- Suchalgorithmus im Suchbaum
|
||||||
|
- welche Verhältnisse müssen zw. den Knoten gelten?
|
||||||
|
- Ansatz bei INSERT und ROTATE, um *ausgeglichenen* Baum
|
||||||
|
mit passenden Verhältnissen zw. Knoten zu erzeugen.
|
||||||
|
|
||||||
### TODOs (Studierende) ###
|
### TODOs (Studierende) ###
|
||||||
|
|
||||||
-
|
- weiter an Pflichtserie3 arbeiten und vor der Frist abgeben.
|
||||||
|
|||||||
Reference in New Issue
Block a user