#include #include #include #include #include #include #include #include "sStack.h" #include "sCPU.h" #include "const_gurd.h" using std::cout; using std::endl; //======================================== /*! Constructor of stack struct \param stack pointers */ void Stack_constructor (sStack *stack) { stack->memory_guard_first = guard_first; stack->memory_guard_second = guard_second; stack->memory_guard_third = guard_third; stack->counter_change_number = 0; stack->top = 0; for (int i = 0; i < stack->MAX_STACK_SIZE; i++) { stack->data [i] = -999; } } //======================================== /*! Destructor of stack struct \param stack pointers */ void Stack_destructoin (sStack *stack) { stack->top = -100; stack->counter_change_number = 0; for (int i = 0; i < stack->MAX_STACK_SIZE; i++) { stack->data [i] = -100500; } } //======================================== /*! The function is showing stack \param stack pointers */ void sStack_show (const sStack *stack) { cout << "top = " << stack->top << endl; cout << "counter_change_number = " << stack->counter_change_number << endl; for (int i = 0; i < stack->MAX_STACK_SIZE; i++ ) { cout << "data " << i << " " << stack->data [i] << "\n"; } cout << endl; } //======================================== /*! The function is showing the last element of stack and do not remove it \param stack pointers \return the value of the last element in stack */ double sStack_show_last_element (const sStack *stack) { if (sStack_size (stack) < 1 ) { processing_error (no_element); return 0; } double last_element = stack->data [(stack->top) - 1]; #ifdef USE_SUPER_PUPER_GUARDS _ASSERT_OK_(sStack, stack) #endif return last_element; } //======================================== /*! THe function is showing the size of stack \param stack pointers */ int sStack_size (const sStack *stack) { //cout << "Stack size: " << stack->top << endl; #ifdef USE_SUPER_PUPER_GUARDS _ASSERT_OK_(sStack, stack) #endif return stack->top; } //======================================== /*! The function add one more number in stack \param stack pointers \param vell the new number */ void sStack_Push (sStack *stack, double vell) { #ifdef USE_SUPER_PUPER_GUARDS _ASSERT_OK_(sStack, stack) #endif if (stack->data [stack->top] == -999 ) { stack->counter_change_number++; } stack->data [stack->top++] = vell; #ifdef USE_SUPER_PUPER_GUARDS _ASSERT_OK_(sStack, stack) #endif /* if (!sStack_Ok (stack)) { sStack_show (stack); _DEBUG_ASSERT_("Stack overflow!"); } */ } //======================================== /*! The function return the last element in stack \param stack pointers \return the last element in stack */ double sStack_Pop (sStack *stack) { double last_element = stack->data [(stack->top) - 1]; //cout << "last_element = " << last_element << endl; stack->data [(stack->top) - 1] = 0; stack->top--; #ifdef USE_SUPER_PUPER_GUARDS _ASSERT_OK_(sStack, stack) #endif return last_element; } //======================================== /*! The function Check stack \param stack pointers \return bool parameter true io all OK */ bool sStack_Ok (const sStack *stack) { if ((stack->top < 0) || (stack->top > stack->MAX_STACK_SIZE)) { return false; } if (stack->memory_guard_first != guard_first || stack->memory_guard_second != guard_second || stack->memory_guard_third != guard_third) { cout << "!!! boundary constants are change !!! \n"; return false; } int counter = 0; for (int i = 0; i < stack->MAX_STACK_SIZE; i++) { if (stack->data [i] == -999) { counter++; } } if ((stack->MAX_STACK_SIZE - stack->counter_change_number) != counter) { cout << "!!!WARNING!!! counter_change_number != counter /n"; } return true; }