Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/general/evaluation/c-stack.c

    r4c80a75 r860f19f  
    22#include "c-stack.h"
    33
    4 typedef struct node {
     4struct stack_node {
    55        void * value;
    6         struct node * next;
    7 } node;
     6        struct stack_node * next;
     7};
    88
    9 void copy_stack( stack * s, const stack * t, void * (*copy)( const void * ) ) {
    10         node ** cr = &s->head;
    11         for ( node * nx = t->head; nx; nx = nx->next ) {
    12                 *cr = malloc( sizeof(node) ); /***/
    13                 (*cr)->value = copy( nx->value );
    14                 cr = &(*cr)->next;
    15         }
    16         *cr = NULL;
    17 }
    18 
    19 void clear_stack( stack * s, void (* free_el)( void * ) ) {
    20         for ( node * nx = s->head; nx; ) {
    21                 node * cr = nx;
    22                 nx = cr->next;
    23                 free_el( cr->value );
    24                 free( cr );
     9void clear_stack( struct stack * s, void (*free_el)( void * ) ) {
     10        for ( struct stack_node * next = s->head; next; ) {
     11                struct stack_node * crnt = next;
     12                next = crnt->next;
     13                free_el( crnt->value );
     14                free( crnt );
    2515        }
    2616        s->head = NULL;
    2717}
    2818
    29 stack new_stack() {
    30         return (stack){ NULL }; /***/
     19struct stack new_stack() { return (struct stack){ NULL }; /***/ }
     20
     21void copy_stack( struct stack * s, const struct stack * t, void * (*copy)( const void * ) ) {
     22        struct stack_node ** crnt = &s->head;
     23        for ( struct stack_node * next = t->head; next; next = next->next ) {
     24                *crnt = malloc( sizeof(struct stack_node) ); /***/
     25                (*crnt)->value = copy( next->value );
     26                crnt = &(*crnt)->next;
     27        }
     28        *crnt = NULL;
    3129}
    32 
    33 stack * assign_stack( stack * s, const stack * t,
     30struct stack * assign_stack( struct stack * s, const struct stack * t,
    3431                void * (*copy_el)( const void * ), void (*free_el)( void * ) ) {
    3532        if ( s->head == t->head ) return s;
     
    3936}
    4037
    41 _Bool stack_empty( const stack * s ) {
    42         return s->head == NULL;
    43 }
     38_Bool stack_empty( const struct stack * s ) { return s->head == NULL; }
    4439
    45 void push_stack( stack * s, void * v ) {
    46         node * n = malloc( sizeof(node) ); /***/
    47         *n = (node){ v, s->head }; /***/
     40void push_stack( struct stack * s, void * v ) {
     41        struct stack_node * n = malloc( sizeof(struct stack_node) ); /***/
     42        *n = (struct stack_node){ v, s->head }; /***/
    4843        s->head = n;
    4944}
    5045
    51 void * pop_stack( stack * s ) {
    52         node * n = s->head;
     46void * pop_stack( struct stack * s ) {
     47        struct stack_node * n = s->head;
    5348        s->head = n->next;
    5449        void * v = n->value;
Note: See TracChangeset for help on using the changeset viewer.