Esempio n. 1
0
void stack_push(int x)
{
      if(!stack_is_full())
         s.top++=x;
      else 
         return error;
}
Esempio n. 2
0
static char * test_initial_state() {
  stack_reset();
  /* test multiple braces */
  sprintf(msg, "ERROR: %d: init_state: should not be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: init_state: should not be full", __LINE__);
  mu_assert(msg, ! stack_is_full());

  push(1);
  sprintf(msg, "ERROR: %d: init_state: should not be empty", __LINE__);
  mu_assert(msg, ! stack_is_empty());
  sprintf(msg, "ERROR: %d: init_state: should not be full", __LINE__);
  mu_assert(msg, ! stack_is_full());

  return EXIT_SUCCESS;
}
Esempio n. 3
0
int main(void) {
	int x;	

void stack_push(int x);
int stack_pop();
int stack_capacity();
int stack_size();
int stack_is_empty();
int stack_is_full();


        while ( ! stack_is_full() ) {
		scanf("%d", &x);
		stack_push(x);
	}
	

	while ( !stack_is_empty() ) {
		x = stack_pop();

		printf("%d\t", x);
	}
	printf("\n");

	return 0;
}
Esempio n. 4
0
void stack_push(struct stack *s, const char e)
{
    if (stack_is_full(s))
        return;

    s->top = s->top + 1;
    *(s->buffer + s->top) = e;
}
Esempio n. 5
0
void stack_push(Stack *s, int x){
    if (stack_is_full(s) != 0)
        return;
    else{
        *(s->top) = x;
        s->top++;
    }
}
static void stack_array_ops_push(struct stack *stack, struct data_node *node)
{
	struct stack_array *a_stack_array = container_of(stack, typeof(*a_stack_array), stack);
	
	_MY_TRACE_STR("stack_array::push()\n");
	if (!stack_is_full(stack))
		a_stack_array->arr[a_stack_array->top++] = node;
}
Esempio n. 7
0
File: stack.c Progetto: burnsba/EBE
stack_item stack_pop(stack* s)
{
	if (stack_is_full(s))
	{
		fprintf(stderr, "Can't pop element from stack: stack is empty.\n");
		exit(1);
	}

	return s->contents[s->top--];
}
Esempio n. 8
0
File: stack.c Progetto: burnsba/EBE
void stack_push(stack* s, stack_item item)
{
	if (stack_is_full(s))
	{
		fprintf(stderr, "Can't push element on stack: stack is full.\n");
		exit(1);
	}
	
	s->contents[++s->top] = item;
}
Esempio n. 9
0
void stack_push(stack_t *stack, stack_element element, stack_error_t *error)
{
	if (stack_is_full(stack)) 
	{
		*error = ESTACKFULL;
	}
	
	*error = SUCCESS;
	stack->contents[++stack->top] = element;
}
Esempio n. 10
0
static char * test_push_till_full() {
  int i = 0;

  stack_reset();

  for (i = 0; i < MAX_INTSTACK - 1; i++) {
    push(i);
    sprintf(msg, "ERROR: %d: iter %d: push_till_full: should not be full", __LINE__, i);
    mu_assert(msg, ! stack_is_full());
    sprintf(msg, "ERROR: %d: iter %d: push_till_full: should not be full", __LINE__, i);
    mu_assert(msg, ! stack_is_empty());
  }

  push(INT_MAX);

  sprintf(msg, "ERROR: %d: push_till_full: should not be empty", __LINE__);
  mu_assert(msg, ! stack_is_empty());
  sprintf(msg, "ERROR: %d: push_till_full: should be full", __LINE__);
  mu_assert(msg, stack_is_full());

  return EXIT_SUCCESS;
}
Esempio n. 11
0
int stack_push(stack_class *stack, void *element, int element_type)
{
  if(stack_is_full(stack))
    {
      WARNING("Cannot push element because stack is full");
      return ERROR;
  }

  // update top
  stack->top++;
  // add element to stack
  (stack->elements[stack->top]).element = element;
  (stack->elements[stack->top]).element_type = element_type;

  return SUCCESS;
}
Esempio n. 12
0
int push(stack* stk, double a){

	if (stack_is_valide(stk)) {
	
		if (stack_is_full(stk)){
		
			errno = EACCES;
			return -2;
		
		}
	
		(stk -> data)[stk -> head + 1] = a;
		(stk -> head)++;
		return 0;
	}
	return -1;
}
Esempio n. 13
0
int main(void) {
	int x;	
	printf("请输入整数,作为要入栈的内容\n");
        while ( ! stack_is_full() ) {
		scanf("%d", &x);
		stack_push(x);
	}
	
	printf("栈满,下面将输出栈里面的内容\n");
	while ( !stack_is_empty() ) {
		x = stack_pop();

		printf("%d\t", x);
	}
	printf("\n");

	return 0;
}
Esempio n. 14
0
int main(void) {
	int x;	
	SqStack s;
	if(InitStack(s)==0)
		return 0;
        while ( ! stack_is_full(s) ) {
		scanf("%d", &x);
		stack_push(x);
	}
	

	while ( !stack_is_empty(s) ) {
		x = stack_pop();

		printf("%d\t", x);
	}
	printf("\n");

	return 0;
}
Esempio n. 15
0
int main() {
	int x;	
    
    printf("Capacity: %d\n", stack_capacity());

    while (!stack_is_full() ) {
		scanf("%d", &x);
		stack_push(x);
        printf("Current Size after fill in: %d\n", stack_size());
	}
	
    printf("Now goes popping!\n");
	while (!stack_is_empty() ) {
		x = stack_pop();
		printf("%d\n", x);
	}
	printf("\n");

	return 0;
}
Esempio n. 16
0
int push(stack* stk, byte a){

	if (stack_is_valide(stk)) {
	
		if (stack_is_full(stk)){
		
			errno = EACCES;
			stack_errno = FULL;
			stack_dump(stk, stack_errno);
			
			return -2;
		
		}
	
		(stk -> data)[stk -> head + 1] = a;
		(stk -> head)++;
		
	if (stack_is_valide(stk)) return 0;
	}
	return -1;
}
Esempio n. 17
0
include <stdio.h>

#include "include/my_stack.h"

int main(void) {
        int x;

        while ( ! stack_is_full() ) {
                scanf("%d", &x);
                stack_push(x);
        }


        while ( !stack_is_empty() ) {
                x = stack_pop();

                printf("%d\t", x);
        }
        printf("\n");

        return 0;
}
Esempio n. 18
0
static char * test_peek() {
  stack_reset();

  // peek should return INT_MIN (with warning) when intstack is empty
  sprintf(msg, "ERROR: %d: peek should return INT_MIN when empty", __LINE__);
  mu_assert(msg, peek() == INT_MIN);
  
  push(55);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);

  push(56);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 56);
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 56);

  sprintf(msg, "ERROR: %d: push_till_full: should not be empty", __LINE__);
  mu_assert(msg, ! stack_is_empty());
  sprintf(msg, "ERROR: %d: push_till_full: should not be full", __LINE__);
  mu_assert(msg, ! stack_is_full());

  pop();
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == 55);

  pop();
  sprintf(msg, "ERROR: %d: peek should return expected", __LINE__);
  mu_assert(msg, peek() == INT_MIN);

  return EXIT_SUCCESS;
}
Esempio n. 19
0
void push(STACK_ELEMENT_T element, Stack_t *stack)
{
    assert(!stack_is_full(stack));
    stack->array[++stack->top_of_stack] = element;
}
Esempio n. 20
0
static char * test_push_pop() {
  int i;

  stack_reset();

  /* push one, pop one */
  push(INT_MAX);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MAX);
  sprintf(msg, "ERROR: %d: should be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: should pop INT_MIN when empty", __LINE__);
  mu_assert(msg, pop() == INT_MIN);
  sprintf(msg, "ERROR: %d: should pop INT_MIN when empty", __LINE__);
  mu_assert(msg, pop() == INT_MIN);
  

  /* push three, pop two */
  push(INT_MAX);
  push(-1);
  push(44);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 44);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == -1);
  
  /* push three, pop one */
  push(1);
  push(2);
  push(3);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 3);

  /* should have three on intstack - add till full */
  for (i = 30; ! stack_is_full(); i++) {
    push(i);
  }

  sprintf(msg, "ERROR: %d: should be full", __LINE__);
  mu_assert(msg, stack_is_full());

  /* now pop all remaining and test values */
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 36);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 35);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 34);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 33);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 32);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 31);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 30);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 2);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == 1);
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MAX);
  sprintf(msg, "ERROR: %d: should be empty", __LINE__);
  mu_assert(msg, stack_is_empty());
  sprintf(msg, "ERROR: %d: should pop expected", __LINE__);
  mu_assert(msg, pop() == INT_MIN);


  return EXIT_SUCCESS;
}