diff src/llrb/stack.h @ 69:368306e1bfed

llrb deletion(not work).
author Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp>
date Tue, 20 Oct 2015 16:22:42 +0900
parents 390cf0523ea7
children 5c4b9d116eda
line wrap: on
line diff
--- a/src/llrb/stack.h	Tue Sep 15 15:21:50 2015 +0900
+++ b/src/llrb/stack.h	Tue Oct 20 16:22:42 2015 +0900
@@ -1,4 +1,4 @@
-#include <string.h>
+#include <stdlib.h>
 
 typedef struct {
     size_t size;
@@ -7,68 +7,11 @@
     void* data;
 } stack, *stack_ptr;
 
-stack_ptr stack_init(size_t size, int max) {
-    stack_ptr stack_ptr;
-    
-    if ((stack_ptr = calloc(1, sizeof(stack))) == NULL)
-        return NULL;
-    
-    if ((stack_ptr->data = calloc(max, size)) == NULL) {
-        free(stack_ptr);
-        return NULL;
-    }
-
-    stack_ptr->size = size;
-    stack_ptr->max = max;
-    stack_ptr->num = 0;
-
-    return stack_ptr;
-}
-
-stack_ptr stack_realloc(stack_ptr stack_ptr, int max) {
-    if (stack_ptr == NULL)
-        return NULL;
-
-    if ((stack_ptr->data = realloc(stack_ptr->data, stack_ptr->size*max)) == NULL)
-        return NULL;
-
-    stack_ptr->max = max;
-
-    return stack_ptr;
-}
+extern stack_ptr stack_init();
+extern stack_ptr stack_realloc();
+extern void stack_free();
+extern int stack_push();
+extern int stack_pop();
+extern int isMax();
+extern int isEmpty();
 
-void stack_free(stack_ptr stack_ptr) {
-    if (stack_ptr != NULL && stack_ptr->data != NULL) {
-        free(stack_ptr->data);
-        free(stack_ptr);
-    }
-}
-    
-int stack_push(stack_ptr stack_ptr, void* data) {
-    if (stack_ptr->max <= stack_ptr->num)
-        return -1;
-
-    memcpy((char*)stack_ptr->data+stack_ptr->num*stack_ptr->size,  data, stack_ptr->size);
-    stack_ptr->num++;
-
-    return 0;
-}
-
-int stack_pop(stack_ptr stack_ptr, void* data) {
-    if (stack_ptr->num == 0)
-        return -1;
-
-    stack_ptr->num--;
-
-    memcpy(data, (char*)stack_ptr->data+stack_ptr->num*stack_ptr->size, stack_ptr->size);
-
-    return 0;
-}
-
-int isMax(const stack_ptr stack_ptr) {
-    return stack_ptr->max<=stack_ptr->num;
-}
-
-int isEmpty(const stack_ptr stack_ptr) {
-    return stack_ptr->num<=0;
-}