int main() { struct card_t card_to_push; struct deck_t player_deck; player_deck.top = 0; struct card_t card; struct card_t one = { "card_one", 1, 7, 0 }; struct card_t two = { "card_two", 3, 7, 4 }; struct card_t three = { "card_three", 4, 6, 4}; printf("is stack empty? = %d\n", is_stack_empty(&player_deck)); printf("is stack full? = %d\n", is_stack_full(&player_deck)); push_card(one, &player_deck); push_card(two, &player_deck); push_card(three, &player_deck); print_stack(&player_deck); printf("\nis stack empty? = %d\n", is_stack_empty(&player_deck)); printf("is stack full? = %d\n", is_stack_full(&player_deck)); //--------------------------------- draw_card(&player_deck); look_card(&player_deck); print_stack(&player_deck); printf("\nis stack empty? = %d\n", is_stack_empty(&player_deck)); printf("is stack full? = %d\n", is_stack_full(&player_deck)); return 0; }
void push_object(LispObject object) { if (is_stack_full()) { write_format(standard_error, "Stack Overflow\n"); exit(1); } global_stack[++global_stack_top] = object; }
void push(element_type x, STACK S){ if(is_stack_full(S)){ printf("stack is full\n"); exit(1); } else S->stack_array[++S->top_of_stack] = x; }
void push(char x) { if (is_stack_full()) { TM_PRINTF("java.out_of_memory_error", NULL); exit(1); } stack[stack_size++] = x; }
bool mystack::push(const data_type &_data)// push data { if( !is_stack_full() || stack_realloc() ){ *top = _data; top++; return true; }else{ return false; } }
void enqueue(element_type x, QUEUE Q){ //both S1 and S2 are full if(is_stack_full(Q->S1)&&(is_stack_full(Q->S2))){ printf("queue is full\n"); exit(1); } // S1 is full while S2 is not if((is_stack_full(Q->S1))&&(!is_stack_full(Q->S2))){ while(!is_stack_full(Q->S2)){ push(pop(Q->S1), Q->S2); } push(x, Q->S1); } if((!is_stack_full(Q->S1))&&(!is_stack_full(Q->S2))){ push(x, Q->S1); } }
// create and use a stack void test_stack() { DEBUG_PRINT("\ntest_stack:\n"); vertex a; a.element = 'a'; vertex b; b.element = 'b'; DEBUG_PRINT(" push 2 nodes...\n"); push(&a); push(&b); DEBUG_PRINT(" pop them off...\n"); vertex* c = pop(); assert(c->element == 'b'); vertex* d = pop(); assert(d->element == 'a'); DEBUG_PRINT(" ensure stack is empty...\n"); assert(is_stack_empty()); DEBUG_PRINT(" fill the stack...\n"); int i; for (i = 0; i < MAX_STACK_SIZE; i++) { push(NULL); } assert(is_stack_full()); empty_stack(); assert(is_stack_empty()); printf("+ stack test passed!\n"); }