Merge remote-tracking branch 'origin/RMax' into tobi_experimental
This commit is contained in:
commit
382c36b1b4
18
.vscode/c_cpp_properties.json
vendored
Normal file
18
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "windows-gcc-x64",
|
||||||
|
"includePath": [
|
||||||
|
"${workspaceFolder}/**"
|
||||||
|
],
|
||||||
|
"compilerPath": "C:/ProgramData/mingw64/mingw64/bin/gcc.exe",
|
||||||
|
"cStandard": "${default}",
|
||||||
|
"cppStandard": "${default}",
|
||||||
|
"intelliSenseMode": "windows-gcc-x64",
|
||||||
|
"compilerArgs": [
|
||||||
|
""
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
24
.vscode/launch.json
vendored
Normal file
24
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "C/C++ Runner: Debug Session",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"args": [],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"externalConsole": true,
|
||||||
|
"cwd": "c:/Users/Max-R/I2Pr/info2Praktikum-DobleSpiel",
|
||||||
|
"program": "c:/Users/Max-R/I2Pr/info2Praktikum-DobleSpiel/build/Debug/outDebug",
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"miDebuggerPath": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
59
.vscode/settings.json
vendored
Normal file
59
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
{
|
||||||
|
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||||
|
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||||
|
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||||
|
"C_Cpp_Runner.cStandard": "",
|
||||||
|
"C_Cpp_Runner.cppStandard": "",
|
||||||
|
"C_Cpp_Runner.msvcBatchPath": "C:/Program Files/Microsoft Visual Studio/VR_NR/Community/VC/Auxiliary/Build/vcvarsall.bat",
|
||||||
|
"C_Cpp_Runner.useMsvc": false,
|
||||||
|
"C_Cpp_Runner.warnings": [
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Wpedantic",
|
||||||
|
"-Wshadow",
|
||||||
|
"-Wformat=2",
|
||||||
|
"-Wcast-align",
|
||||||
|
"-Wconversion",
|
||||||
|
"-Wsign-conversion",
|
||||||
|
"-Wnull-dereference"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.msvcWarnings": [
|
||||||
|
"/W4",
|
||||||
|
"/permissive-",
|
||||||
|
"/w14242",
|
||||||
|
"/w14287",
|
||||||
|
"/w14296",
|
||||||
|
"/w14311",
|
||||||
|
"/w14826",
|
||||||
|
"/w44062",
|
||||||
|
"/w44242",
|
||||||
|
"/w14905",
|
||||||
|
"/w14906",
|
||||||
|
"/w14263",
|
||||||
|
"/w44265",
|
||||||
|
"/w14928"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.enableWarnings": true,
|
||||||
|
"C_Cpp_Runner.warningsAsError": false,
|
||||||
|
"C_Cpp_Runner.compilerArgs": [],
|
||||||
|
"C_Cpp_Runner.linkerArgs": [],
|
||||||
|
"C_Cpp_Runner.includePaths": [],
|
||||||
|
"C_Cpp_Runner.includeSearch": [
|
||||||
|
"*",
|
||||||
|
"**/*"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.excludeSearch": [
|
||||||
|
"**/build",
|
||||||
|
"**/build/**",
|
||||||
|
"**/.*",
|
||||||
|
"**/.*/**",
|
||||||
|
"**/.vscode",
|
||||||
|
"**/.vscode/**"
|
||||||
|
],
|
||||||
|
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||||
|
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||||
|
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||||
|
"C_Cpp_Runner.showCompilationTime": false,
|
||||||
|
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||||
|
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||||
|
}
|
||||||
BIN
doble_initial.exe
Normal file
BIN
doble_initial.exe
Normal file
Binary file not shown.
2
makefile
2
makefile
@ -35,7 +35,7 @@ $(program_obj_files): %.o: %.c
|
|||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
|
unitTests:
|
||||||
TEST_BIN = runTests
|
TEST_BIN = runTests
|
||||||
|
|
||||||
unitTests: stack.o test_stack.o
|
unitTests: stack.o test_stack.o
|
||||||
|
|||||||
BIN
runTests.exe
Normal file
BIN
runTests.exe
Normal file
Binary file not shown.
39
stack.c
39
stack.c
@ -10,15 +10,13 @@
|
|||||||
} StackNode;*/
|
} StackNode;*/
|
||||||
|
|
||||||
// TODO: grundlegende Stackfunktionen implementieren:
|
// TODO: grundlegende Stackfunktionen implementieren:
|
||||||
/* `push`: legt ein Element oben auf den Stack,
|
/* * `push`: legt ein Element oben auf den Stack,
|
||||||
* `pop`: entfernt das oberste Element,
|
* `pop`: entfernt das oberste Element,
|
||||||
* `top`: liefert das oberste Element zurück,
|
* `top`: liefert das oberste Element zurück,
|
||||||
* `clearStack`: gibt den gesamten Speicher frei. */
|
* `clearStack`: gibt den gesamten Speicher frei. */
|
||||||
|
|
||||||
// [A] -> [B] -> [C] -> NULL
|
StackNode *createNode(void *data)
|
||||||
// head -> stack.next
|
{
|
||||||
|
|
||||||
StackNode *createNode(void *data) {
|
|
||||||
|
|
||||||
StackNode *node =
|
StackNode *node =
|
||||||
malloc(sizeof(StackNode)); // Speicher reservieren, Speicherplatz für das
|
malloc(sizeof(StackNode)); // Speicher reservieren, Speicherplatz für das
|
||||||
@ -34,12 +32,13 @@ StackNode *createNode(void *data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data) {
|
StackNode *push(StackNode *stack, void *data)
|
||||||
|
{
|
||||||
StackNode *newNode = createNode(data); // Speicher für neuen Knoten
|
StackNode *newNode = createNode(data); // Speicher für neuen Knoten
|
||||||
// reservieren
|
// reservieren
|
||||||
|
|
||||||
if (newNode == NULL) { // wenn Speicher nicht reserviert werden konnte, wird
|
if (newNode == NULL)
|
||||||
|
{ // wenn Speicher nicht reserviert werden konnte, wird
|
||||||
// stack unverändert zurückgegeben
|
// stack unverändert zurückgegeben
|
||||||
return stack;
|
return stack;
|
||||||
}
|
}
|
||||||
@ -49,10 +48,10 @@ StackNode *push(StackNode *stack, void *data) {
|
|||||||
return newNode; // Zeiger auf neuen Speicherbereich zurückgeben
|
return newNode; // Zeiger auf neuen Speicherbereich zurückgeben
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deletes the top element of the stack (latest added element) and releases its
|
// Deletes the top element of the stack (latest added element) and releases its memory. (Pointer to data has to be
|
||||||
// memory. (Pointer to data has to be freed by caller.)
|
// freed by caller.)
|
||||||
StackNode *pop(StackNode *stack) {
|
StackNode *pop(StackNode *stack)
|
||||||
|
{
|
||||||
if (stack == NULL)
|
if (stack == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -69,18 +68,16 @@ StackNode *pop(StackNode *stack) {
|
|||||||
void *top(StackNode *stack) { return stack != NULL ? stack->data : NULL; }
|
void *top(StackNode *stack) { return stack != NULL ? stack->data : NULL; }
|
||||||
|
|
||||||
// Clears stack and releases all memory.
|
// Clears stack and releases all memory.
|
||||||
void clearStack(StackNode *stack) {
|
void clearStack(StackNode *stack)
|
||||||
|
{
|
||||||
while (stack != NULL) {
|
while (stack != NULL)
|
||||||
|
{
|
||||||
|
|
||||||
StackNode *next = stack->next;
|
StackNode *next = stack->next;
|
||||||
stack->data = NULL;
|
|
||||||
stack->prev = NULL;
|
|
||||||
stack->next = NULL;
|
|
||||||
|
|
||||||
free(stack);
|
free(stack);
|
||||||
stack = next;
|
stack = next;
|
||||||
|
stack->data = NULL;
|
||||||
|
stack->next = NULL;
|
||||||
|
stack->prev = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
10
stack.h
10
stack.h
@ -19,6 +19,16 @@ typedef struct StackNode {
|
|||||||
|
|
||||||
StackNode *createNode(void *data);
|
StackNode *createNode(void *data);
|
||||||
|
|
||||||
|
typedef struct StackNode {
|
||||||
|
|
||||||
|
void *data;
|
||||||
|
struct StackNode *next;
|
||||||
|
struct StackNode *prev;
|
||||||
|
|
||||||
|
} StackNode;
|
||||||
|
|
||||||
|
StackNode *createNode(void *data);
|
||||||
|
|
||||||
// Pushes data as pointer onto the stack.
|
// Pushes data as pointer onto the stack.
|
||||||
StackNode *push(StackNode *stack, void *data);
|
StackNode *push(StackNode *stack, void *data);
|
||||||
|
|
||||||
|
|||||||
BIN
test_stack.o
Normal file
BIN
test_stack.o
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user