Написание калькулятора с разбором выражений, страница 7

      struct __stack_list__ *PointerToPrevious; /* POINTER TO PREVIOUS ELEMENT */

    }*STACK_LIST, *PointerToCurrent;            /* POINTER TO STACK,

                                                   POINTER TO CURRENT ELEMENT*/

    /* END OF '__stack_list__' STRUCTURE DEFINITION */

  public:

    /* DEFAULT CTOR DEFINITION */

    STACK ()

    {

      ElemetsQuantity = 0;

    }

    /* END OF DEFAULT CTOR DEFINITION */

    /* DTOR DEFINITION */

    ~STACK ()

    {

    }

    /* END OF DTOR DEFINITION */

  public:

    /* THIS FUNCTION RETURNS QUANTITY OF ELEMENTS IN STACK */

    int TOP (void)

    {

      return ElemetsQuantity;

    }

    /* END OF 'TOP' DEFININITION */

    /* THIS FUNCTION PUSH ELEMENT TO STACK */

    void PUSH (TYPE Argument)

    {

      if (ElemetsQuantity == 0)

      {

        STACK_LIST = PointerToCurrent = (struct __stack_list__*)malloc (sizeof (struct __stack_list__));

        PointerToCurrent->PointerToPrevious = PointerToCurrent;

        PointerToCurrent->PointerToNext   =   NULL;

        PointerToCurrent->Var = Argument;

      }

      else

      {

        PointerToCurrent->PointerToNext = (struct __stack_list__*)malloc (sizeof (struct __stack_list__));

        PointerToCurrent->PointerToNext->PointerToPrevious = PointerToCurrent;

        PointerToCurrent = PointerToCurrent->PointerToNext;

        PointerToCurrent->Var = Argument;

      }

      ElemetsQuantity++;

    }

    /* END OF 'PUSH' DEFINITION */

    /* THIS FUNCTION POP ELEMENT FROM STACK */

    TYPE POP (void)

    {

      TYPE RES;

      if (ElemetsQuantity == 0)

        return NULL;

      RES = PointerToCurrent->Var;

      PointerToCurrent = PointerToCurrent->PointerToPrevious;

      if (ElemetsQuantity == 1)

        free (PointerToCurrent);

      else

        free (PointerToCurrent->PointerToNext);

      ElemetsQuantity--;

      return RES;

    }

    /* END OF 'POP' DEFINITION */

    /* THIS FUNCTION RETURNS LAST ELEMENT */

    TYPE LastElem (void)

    {

      if (ElemetsQuantity  > 0)

        return PointerToCurrent->Var;

      return NULL;

    }

    /* END OF'LastElem' DEFINITION */

    /* THIS FUNCTION RETURNS PREVIOUS ELEMENT */

    TYPE PrevElem (void)

    {

      if (ElemetsQuantity > 1)

        return PointerToCurrent->PointerToPrevious->Var;

      return NULL;

    }

    /* END OF 'PrevElem' DEFINITION */

};

/* END OF 'SATCK' CLASS DEFINITION */

#endif

/* END OF 'STACK.H' */

/********************************************************************

*  Copyright (C) 2004 - 2005

*  Hizov Software

*  Falling Anvil GRP Support Group

********************************************************************/

/********************************************************************

* FILE NAME           : TEDIT.H

* PURPOSE             : TEXT EDIT METHODS DEFINITION

* PROGRAMMER          : MIHAIL A. HIZOV

* LAST UPDATE         : 17.10.2005 20:20

* VERSION             : 1.3

* FILE SIZE           : 6903 Bytes

* TOTAL PROGECT SIZE  :    -

* NOTE                : NO MODULE PREFIX DEFINED

*                       MAIN CLASS IS 'ITextEditor'

*

* No part of this file may be changed without agreement of

* Mihail A. Hizov Personally

********************************************************************/