Changeset 154fdc8 for doc/generic_types/evaluation/c-stack.c
- Timestamp:
- Apr 19, 2017, 10:15:45 AM (9 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- cd348e7
- Parents:
- 221c2de7 (diff), de4ce0e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
doc/generic_types/evaluation/c-stack.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
doc/generic_types/evaluation/c-stack.c
r221c2de7 r154fdc8 7 7 }; 8 8 9 struct stack new_stack() { 10 return (struct stack){ NULL }; 9 struct stack new_stack() { return (struct stack){ NULL }; /***/ } 10 11 void copy_stack(struct stack* s, const struct stack* t, void* (*copy)(const void*)) { 12 struct stack_node** crnt = &s->head; 13 struct stack_node* next = t->head; 14 while ( next ) { 15 *crnt = malloc(sizeof(struct stack_node)); /***/ 16 **crnt = (struct stack_node){ copy(next->value) }; /***/ 17 crnt = &(*crnt)->next; 18 next = next->next; 19 } 20 *crnt = 0; 11 21 } 12 22 13 void clear_stack(struct stack* s ) {23 void clear_stack(struct stack* s, void (*free_el)(void*)) { 14 24 struct stack_node* next = s->head; 15 25 while ( next ) { 16 26 struct stack_node* crnt = next; 17 27 next = crnt->next; 18 free (crnt->value);28 free_el(crnt->value); 19 29 free(crnt); 20 30 } 31 s->head = NULL; 21 32 } 22 33 23 _Bool stack_empty(const struct stack* s) { 24 return s->head == NULL; 25 } 34 _Bool stack_empty(const struct stack* s) { return s->head == NULL; } 26 35 27 36 void push_stack(struct stack* s, void* value) { 28 struct stack_node* n = malloc(sizeof(struct stack_node)); 29 *n = (struct stack_node){ value, s->head }; 37 struct stack_node* n = malloc(sizeof(struct stack_node)); /***/ 38 *n = (struct stack_node){ value, s->head }; /***/ 30 39 s->head = n; 31 40 }
Note:
See TracChangeset
for help on using the changeset viewer.