Commit 1b8ce2a5 authored by jonas.stirnema's avatar jonas.stirnema
Browse files

Added basic stack

parent 304d06f4
No preview for this file type
......@@ -44,6 +44,25 @@ uint64_t GCD(uint64_t a, uint64_t b)
uint64_t LCM(uint64_t a, uint64_t b)
{
return( a / (GCD(a, b)) * b);
}
/**
* @brief Get the Lowest Common Multiplier Recursivly
*
* @param a
* @param b
* @return int64_t
*/
uint64_t LCMR(uint64_t ma, uint64_t mb, uint64_t a, uint64_t b)
{
// STOP
if(ma == mb){return ma;}
else if(ma > mb){ LCMR(); }
}
......
......@@ -57,12 +57,13 @@ int main()
printf("COMPUTED FACTORIAL IN %lfs\n", timeT);
printf("FACT(%ld) = %ld \n", a, r);
t = clock();
r = fibo(b);
t = clock() - t;
timeT = ((double)t) / CLOCKS_PER_SEC;
printf("COMPUTED FIBO IN %lfs\n", timeT);
printf("FACT(%ld) = %ld \n", a, r);
// // FIBO
// t = clock();
// r = fibo(b);
// t = clock() - t;
// timeT = ((double)t) / CLOCKS_PER_SEC;
// printf("COMPUTED FIBO IN %lfs\n", timeT);
// printf("FACT(%ld) = %ld \n", a, r);
return 0;
......
# * PROJ
# * Author: Jonas S.
# * Date: 11/07/21
# ! OBJECTIVE
# ? CREATE A BASIC RUNNING PROJECT
# ? CREATE SIMPLE C OR HEADER FILE WITH HEADERS
# ? CREATE MAKEFILE
# ! NEED COLORAMA AND OS
import colorama
from colorama import Fore, Back
#HARD CODED STUFF
NAME = "Jonas S."
colorama.init()
# ! FILE CREATION
def createFile(fileName, content):
with open(f"{fileName}", 'w', encoding = 'utf-8') as f:
f.write(content)
def createHeaderFile(fileName):
from datetime import datetime
import os
from os import mkdir
now = datetime.now() # current date and time
content = (
"/*\n"
f"\t* HEADER {fileName.upper()}\n"
f"\t* Author : {NAME}\n"
f"\t* Date : {now.strftime('%d/%m/%Y')}\n"
"\t! DESCRIPTION\n"
"*/\n\n"
f"#ifndef _{fileName.upper()}_H_\n"
f"#define _{fileName.upper()}_H_\n\n"
"// DEFINES\n\n"
"// PROTOTYPE FUNCTIONS\n\n"
"#endif"
)
if not os.path.exists('include'):
mkdir('include')
createFile(f"include/{fileName}.h", content)
def createCodeFile(fileName):
from datetime import datetime
from datetime import datetime
import os
from os import mkdir
now = datetime.now() # current date and time
content = (
"/*\n"
f"\t* CODE {fileName.upper()}\n"
f"\t* Author : {NAME}\n"
f"\t* Date : {now.strftime('%d/%m/%Y')}\n"
"\t! DESCRIPTION\n"
"*/\n\n"
)
# add basic printf if main
if fileName == "main":
content += "#include <stdio.h>\n\nint main()\n{\n\tprintf(\"ISSOU\\n\");\n\treturn 0;\n}"
if not os.path.exists('src'):
mkdir('src')
createFile(f"src/{fileName}.c", content)
def createMakefile():
content = (
"CC := gcc\n"
"CFLAGS := -Wall -Wextra -g -fsanitize=address -fsanitize=leak\n"
"\n"
"BIN := bin\n"
"SRC := src\n"
"INCLUDE := include\n"
"LIBRARIES := -lm\n"
"EXECUTABLE1 := main\n"
"\n"
"# ADD ALL THE SOURCES FOR EXECUTABLE1\n"
"SOURCES1 += $(SRC)/jrandom\n"
"\n"
".PHONY: all run clean # Specify these are not files but internal terms\n"
"\n"
"all: $(BIN)/$(EXECUTABLE1)\n"
"\n"
"run: clean all\n"
" clear\n"
" @echo "########## EXECUTE FIRST PROGRAM ##########"\n"
" ./$(BIN)/$(EXECUTABLE1)\n"
"\n"
"# # $^ -> dep\n"
"# # $@ -> target\n"
"# # $< -> premiere dep\n"
"# # Compiles directly the c files\n"
"# # Not optimal but succint and simple\n"
"\n"
"# COMPILE FIRST EXECUTABLE\n"
"$(BIN)/$(EXECUTABLE1): $(SRC)/$(EXECUTABLE1).c $(SOURCES)\n"
" @echo "########## COMPILING FIRST EXECUTABLE ##########"\n"
" $(CC) $(CFLAGS) -I $(INCLUDE) $^ -o $@ $(LIBRARIES)\n"
"\n"
"clean:\n"
" @echo "########## CLEANING ##########"\n"
" -rm $(BIN)/*\n"
"\n"
)
createFile("Makefile", content)
def createDirStructure():
import os
from os import mkdir
if not os.path.exists('bin'):
mkdir('bin')
if not os.path.exists('build'):
mkdir('build')
if not os.path.exists('include'):
mkdir('include')
if not os.path.exists('src'):
mkdir('src')
# ! MENU CREATION
def createCompleteProject():
# Base structure (SRC, BUILD, INCLUDE, BIN)
createDirStructure()
print(f"{Fore.GREEN}+ BASIC STRUCTURE CREATED{Fore.RESET}")
# Makefile
createMakefile()
print(f"{Fore.GREEN}+ MAKEFILE CREATED{Fore.RESET}")
# Main
createCodeFile("main")
print(f"{Fore.GREEN}+ MAIN.C FILE CREATE{Fore.RESET}")
def createCodeHeader(name):
# Code
createCodeFile(name)
print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}")
# Header
createHeaderFile(name)
print(f"{Fore.GREEN}+ HEADER FILE CREATED{Fore.RESET}")
# ! MENU
def menu():
choice = input(
"1 - COMPLETE PROJECT \n"
"2 - CODE + HEADER \n"
"3 - CODE ONLY \n"
"4 - HEADER ONLY \n"
"5 - MAKEFILE ONLY \n"
"\n"
)
# PROJECT
if choice == '1':
print(f"{Fore.BLUE}FULL PROJECT IS BEING CREATED.{Fore.RESET}")
createCompleteProject()
# CODE + HEADER
elif choice == '2':
print(f"{Fore.BLUE}A CODE AND HEADER FILE ARE BEING CREATED.{Fore.RESET}")
createCodeHeader(input("WHAT FILE NAME DO YOU WANT : "))
# CODE
elif choice == '3':
print(f"{Fore.BLUE}A CODE FILE IS BEING CREATED.{Fore.RESET}")
createCodeFile(input("WHAT FILE NAME DO YOU WANT : "))
print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}")
# HEADER
elif choice == '4':
print(f"{Fore.BLUE}A HEADER FILE IS BEING CREATED.{Fore.RESET}")
createHeaderFile(input("WHAT FILE NAME DO YOU WANT : "))
print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}")
# MAKEFILE
elif choice == '5':
print(f"{Fore.BLUE}A HEADER FILE IS BEING CREATED.")
createMakefile()
print(f"{Fore.GREEN}+ MAKEFILE CREATED{Fore.RESET}")
if __name__ == "__main__":
menu()
CC := gcc
CFLAGS := -Wall -Wextra -g -fsanitize=address -fsanitize=leak
BIN := bin
SRC := src
INCLUDE := include
LIBRARIES := -lm
EXECUTABLE1 := main
# ADD ALL THE SOURCES FOR EXECUTABLE1
SOURCES1 += $(SRC)/jrandom
.PHONY: all run clean # Specify these are not files but internal terms
all: $(BIN)/$(EXECUTABLE1)
run: clean all
clear
@echo "RUN MAIN"
./$(BIN)/$(EXECUTABLE1)
# # $^ -> dep
# # $@ -> target
# # $< -> premiere dep
# # Compiles directly the c files
# # Not optimal but succint and simple
# COMPILE FIRST EXECUTABLE
$(BIN)/$(EXECUTABLE1): $(SRC)/$(EXECUTABLE1).c $(SOURCES)
@echo
$(CC) $(CFLAGS) -I $(INCLUDE) $^ -o $@ $(LIBRARIES)
clean:
@echo
-rm $(BIN)/*
File added
/*
* HEADER STACK
* Author : Jonas S.
* Date : 17/11/2021
! STACK IMPLEMENTATION
*/
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#ifndef _JSTACK_H_
#define _JSTACK_H_
// DEFINES
#define MAX_CAPACITY 500
typedef struct
{
int64_t top;
int32_t *data;
}stack_t;
// PROTOTYPE FUNCTIONS
int32_t* create_stack();
void stack_push(stack_t* st, int32_t val);
int32_t stack_pop(stack_t* st);
int32_t stack_peek(stack_t st);
bool stack_is_full(stack_t st);
bool stack_is_empty(stack_t st);
void stack_destroy(stack_t* st);
#endif
\ No newline at end of file
# * PROJ
# * Author: Jonas S.
# * Date: 11/07/21
# ! OBJECTIVE
# ? CREATE A BASIC RUNNING PROJECT
# ? CREATE SIMPLE C OR HEADER FILE WITH HEADERS
# ? CREATE MAKEFILE
# ! NEED COLORAMA AND OS
import colorama
from colorama import Fore, Back
#HARD CODED STUFF
NAME = "Jonas S."
colorama.init()
# ! FILE CREATION
def createFile(fileName, content):
with open(f"{fileName}", 'w', encoding = 'utf-8') as f:
f.write(content)
def createHeaderFile(fileName):
from datetime import datetime
import os
from os import mkdir
now = datetime.now() # current date and time
content = (
"/*\n"
f"\t* HEADER {fileName.upper()}\n"
f"\t* Author : {NAME}\n"
f"\t* Date : {now.strftime('%d/%m/%Y')}\n"
"\t! DESCRIPTION\n"
"*/\n\n"
f"#ifndef _{fileName.upper()}_H_\n"
f"#define _{fileName.upper()}_H_\n\n"
"// DEFINES\n\n"
"// PROTOTYPE FUNCTIONS\n\n"
"#endif"
)
if not os.path.exists('include'):
mkdir('include')
createFile(f"include/{fileName}.h", content)
def createCodeFile(fileName):
from datetime import datetime
from datetime import datetime
import os
from os import mkdir
now = datetime.now() # current date and time
content = (
"/*\n"
f"\t* CODE {fileName.upper()}\n"
f"\t* Author : {NAME}\n"
f"\t* Date : {now.strftime('%d/%m/%Y')}\n"
"\t! DESCRIPTION\n"
"*/\n\n"
)
# add basic printf if main
if fileName == "main":
content += "#include <stdio.h>\n\nint main()\n{\n\tprintf(\"ISSOU\\n\");\n\treturn 0;\n}"
if not os.path.exists('src'):
mkdir('src')
createFile(f"src/{fileName}.c", content)
def createMakefile():
content = (
"CC := gcc\n"
"CFLAGS := -Wall -Wextra -g -fsanitize=address -fsanitize=leak\n"
"\n"
"BIN := bin\n"
"SRC := src\n"
"INCLUDE := include\n"
"LIBRARIES := -lm\n"
"EXECUTABLE1 := main\n"
"\n"
"# ADD ALL THE SOURCES FOR EXECUTABLE1\n"
"SOURCES1 += $(SRC)/jrandom\n"
"\n"
".PHONY: all run clean # Specify these are not files but internal terms\n"
"\n"
"all: $(BIN)/$(EXECUTABLE1)\n"
"\n"
"run: clean all\n"
" clear\n"
" @echo "########## EXECUTE FIRST PROGRAM ##########"\n"
" ./$(BIN)/$(EXECUTABLE1)\n"
"\n"
"# # $^ -> dep\n"
"# # $@ -> target\n"
"# # $< -> premiere dep\n"
"# # Compiles directly the c files\n"
"# # Not optimal but succint and simple\n"
"\n"
"# COMPILE FIRST EXECUTABLE\n"
"$(BIN)/$(EXECUTABLE1): $(SRC)/$(EXECUTABLE1).c $(SOURCES)\n"
" @echo "########## COMPILING FIRST EXECUTABLE ##########"\n"
" $(CC) $(CFLAGS) -I $(INCLUDE) $^ -o $@ $(LIBRARIES)\n"
"\n"
"clean:\n"
" @echo "########## CLEANING ##########"\n"
" -rm $(BIN)/*\n"
"\n"
)
createFile("Makefile", content)
def createDirStructure():
import os
from os import mkdir
if not os.path.exists('bin'):
mkdir('bin')
if not os.path.exists('build'):
mkdir('build')
if not os.path.exists('include'):
mkdir('include')
if not os.path.exists('src'):
mkdir('src')
# ! MENU CREATION
def createCompleteProject():
# Base structure (SRC, BUILD, INCLUDE, BIN)
createDirStructure()
print(f"{Fore.GREEN}+ BASIC STRUCTURE CREATED{Fore.RESET}")
# Makefile
createMakefile()
print(f"{Fore.GREEN}+ MAKEFILE CREATED{Fore.RESET}")
# Main
createCodeFile("main")
print(f"{Fore.GREEN}+ MAIN.C FILE CREATE{Fore.RESET}")
def createCodeHeader(name):
# Code
createCodeFile(name)
print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}")
# Header
createHeaderFile(name)
print(f"{Fore.GREEN}+ HEADER FILE CREATED{Fore.RESET}")
# ! MENU
def menu():
choice = input(
"1 - COMPLETE PROJECT \n"
"2 - CODE + HEADER \n"
"3 - CODE ONLY \n"
"4 - HEADER ONLY \n"
"5 - MAKEFILE ONLY \n"
"\n"
)
# PROJECT
if choice == '1':
print(f"{Fore.BLUE}FULL PROJECT IS BEING CREATED.{Fore.RESET}")
createCompleteProject()
# CODE + HEADER
elif choice == '2':
print(f"{Fore.BLUE}A CODE AND HEADER FILE ARE BEING CREATED.{Fore.RESET}")
createCodeHeader(input("WHAT FILE NAME DO YOU WANT : "))
# CODE
elif choice == '3':
print(f"{Fore.BLUE}A CODE FILE IS BEING CREATED.{Fore.RESET}")
createCodeFile(input("WHAT FILE NAME DO YOU WANT : "))
print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}")
# HEADER
elif choice == '4':
print(f"{Fore.BLUE}A HEADER FILE IS BEING CREATED.{Fore.RESET}")
createHeaderFile(input("WHAT FILE NAME DO YOU WANT : "))
print(f"{Fore.GREEN}+ CODE FILE CREATED{Fore.RESET}")
# MAKEFILE
elif choice == '5':
print(f"{Fore.BLUE}A HEADER FILE IS BEING CREATED.")
createMakefile()
print(f"{Fore.GREEN}+ MAKEFILE CREATED{Fore.RESET}")
if __name__ == "__main__":
menu()
/*
* CODE MAIN
* Author : Jonas S.
* Date : 17/11/2021
! DESCRIPTION
*/
#include <stdio.h>
int main()
{
printf("ISSOU\n");
return 0;
}
\ No newline at end of file
/*
* CODE STACK
* Author : Jonas S.
* Date : 17/11/2021
! STACK IMPLEMENTATION
*/
#include "../include/stack.h"
int32_t* create_stack()
{
stack_t* st = malloc(sizeof(stack_t));
st->data = malloc(MAX_CAPACITY * sizeof(int32_t));
st->top = -1;
}
void stack_push(stack_t* st, int32_t val)
{
st->data[++st->top] = val;
}
int32_t stack_pop(stack_t* st)
{
return st->data[st->top--];
}
int32_t stack_peek(stack_t st)
{
return st.data[st.top];
}
bool stack_is_full(stack_t st)
{
return st.top == MAX_CAPACITY;
}
bool stack_is_empty(stack_t st)
{
return st.top == -1;
}
void stack_destroy(stack_t* st)
{
free(st->data);
free(st);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment