full stack
This commit is contained in:
parent
ec7edc0f3c
commit
d7b167d7be
@ -5,7 +5,7 @@
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STACK_SIZE 20
|
||||
#define STACK_SIZE 10
|
||||
|
||||
struct stack{
|
||||
float values[STACK_SIZE];
|
||||
@ -27,8 +27,18 @@ int main(){
|
||||
struct stack myStack;
|
||||
memset(&myStack,0,sizeof(struct stack));
|
||||
while(1){
|
||||
if(myStack.size == 9){
|
||||
//print_stack(&myStack);
|
||||
puts("full stack");
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
ptr = fgets(char_value, STACK_SIZE-1, stdin);
|
||||
if(ptr != NULL){
|
||||
|
||||
if(char_value[0] == '\n'){
|
||||
puts("no input");
|
||||
break;
|
||||
@ -105,6 +115,7 @@ int main(){
|
||||
puts("no input");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -118,13 +129,13 @@ void print_stack(struct stack* stack){
|
||||
}
|
||||
|
||||
void push_stack(struct stack* stack, float value){
|
||||
assert(stack->size < STACK_SIZE);
|
||||
//assert(stack->size < STACK_SIZE);
|
||||
stack->values[stack->size] = value;
|
||||
stack->size += 1;
|
||||
}
|
||||
|
||||
float pop_stack(struct stack* stack){
|
||||
assert(stack->size > 0);
|
||||
//assert(stack->size > 0);
|
||||
float value = stack->values[stack->size-1];
|
||||
stack->size -= 1;
|
||||
return value;
|
||||
|
Loading…
Reference in New Issue
Block a user