summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-11-03 01:08:28 +0200
committerRasmus Luha <rasmus.luha@gmail.com>2022-11-03 01:08:28 +0200
commit4bdad2d5c7dec0eb19c418cadb47cc3124092310 (patch)
treec80d9cceb8e10e91daf38657cf64d8ce0bbf3104 /test
parentfcb9ff2b96de6989e9a676e96753b1b1279acf67 (diff)
praks IV doneHEADmaster
Diffstat (limited to 'test')
-rw-r--r--test/stack.c106
-rw-r--r--test/stack.h18
2 files changed, 0 insertions, 124 deletions
diff --git a/test/stack.c b/test/stack.c
deleted file mode 100644
index 8d227f9..0000000
--- a/test/stack.c
+++ /dev/null
@@ -1,106 +0,0 @@
-#include <stdio.h>
-#include "stack.h"
-
-struct stack_st stack = { .len = 0, //prageused el
- .size = 0, // max el
- .arr = NULL};
-
-// Functions
-
-void stackPush(int val){
- if (stack.len == 0 || stack.arr == NULL){
- // Peame küsima mälu
- stack.size = 1;
- stack.arr = malloc(stack.size * sizeof(int));
-
- if (stack.arr == NULL) {
- printf("Mälu otsas\n");
- return;
- }
- stack.arr[stack.len++] = val;
- }
-
- else if (stack.len == stack.size){
- int tmp_size = malloc(2 stack.size);
- int* tmp_arr = realloc(stack.val, tmp_size * sizeof(int));
-
- if (stack.arr == NULL) {
- printf("Mälu otsas\n");
- return;
- }
-
- stack.size = tmp_size;
- stack.arr = tmp_arr;
- stack.arr[stack.len] = val;
- stack.len++;
- return;
- }
-
-}
-
-
-int stackPop(void){
- // Mälu vähendamine
- /*
- return stack.arr[--stack.len];
- */
- // Peaks olema kogu värk.
-
- int x = stack.val[--stack.len]
- int tmp_size = stack.size/2;
- if (stack.len < tmp-size){
- int* tmp_arr = realloc(stack.arr, tmp_size *sizeof(int));
- if (!tmp_arr){
- printf("No good, malu ots");
- return 0;
- }
- stack.size = tmp_size;
- stack.arr = tmp_arr;
-
- if (stack.len == 0)
- stack_free();
-// End of new stuff //
-
- if (stackIsEmpty()){
- return 0;
- }
- int stackPopped = stack.arr[--stack.len];
- return stackPopped;
-}
-
-
-int stackIsEmpty(void) {
- return !(stack.len > 0);
-}
-
-
-int stackPeek(){
- // To avoid funking up the stack.len
- if (stackIsEmpty()) return 0;
- else if (stack.len == 1) return stack.arr[1];
- else{
- int x = stackPop();
- stackPush(x);
- return x;
- }
-}
-
-
-void stackPrint(){
- while(1){
- if(stackIsEmpty())
- break;
-
- int x = stackPop();
- printf("%d\n", x);
- }
- return;
-}
-
-
-/*
-stack_free(){
- free(stack.val); // kutsuda kõige lõpus vist
- stack.arr = NULL;
-}
-*/
diff --git a/test/stack.h b/test/stack.h
deleted file mode 100644
index 8bb1539..0000000
--- a/test/stack.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#ifndef __STACK_H__
-#define __STACK_H__
-
-#define STACK_SIZE 100
-
-struct stack_st {
- int len;
- int size;
- int* arr;
-};
-
-void stackPush(int val);
-int stackPop(void);
-int stackIsEmpty(void);
-int stackPeek(void);
-void stackPrint(void);
-
-#endif