Fixed push().
This commit is contained in:
		
							parent
							
								
									84383a3275
								
							
						
					
					
						commit
						ad737aa765
					
				
							
								
								
									
										12
									
								
								lib/stack.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								lib/stack.c
									
									
									
									
									
								
							| @ -33,16 +33,16 @@ int length(struct stack *stack) { | |||||||
|   return(length); |   return(length); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void push(struct stack *stack, struct card *card) { | void push(struct stack **stack, struct card *card) { | ||||||
|   struct stack *new_stack = NULL; |   struct stack *new_stack = NULL; | ||||||
| 
 | 
 | ||||||
|   if (empty(stack)) { |   if (empty(*stack)) { | ||||||
|     stack->card = card; |     (*stack)->card = card; | ||||||
|   } else { |   } else { | ||||||
|     new_stack = malloc(sizeof(new_stack)); |     new_stack = initialize_stack(); | ||||||
|     new_stack->card = card; |     new_stack->card = card; | ||||||
|     new_stack->next = stack; |     new_stack->next = (*stack); | ||||||
|     stack = new_stack; |     *stack = new_stack; | ||||||
|   } |   } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -9,7 +9,7 @@ struct stack { | |||||||
| struct stack *initialize_stack(); | struct stack *initialize_stack(); | ||||||
| bool empty(struct stack *); | bool empty(struct stack *); | ||||||
| int length(struct stack *); | int length(struct stack *); | ||||||
| void push(struct stack *, struct card *); | void push(struct stack **, struct card *); | ||||||
| struct stack *pop(struct stack *); | struct stack *pop(struct stack *); | ||||||
| 
 | 
 | ||||||
| #endif | #endif | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user