Ask Experts Questions for FREE Help !
Ask
    hulihany2's Avatar
    hulihany2 Posts: 0, Reputation: 1
    New Member
     
    #1

    Oct 15, 2006, 02:12 AM
    stack programming problem
    When I program stack using array in data structure

    This is my data structure
    typedef double stackElementT;
    typedef struct {
    stackElementT elements[STACK_INIT_SIZE];
    int count;
    int size;
    }stackCDT;//data type

    void ExpandStack(stackCDT* stack)
    {
    stackElementT *array;//declare a pointer
    int I,newSize;

    newSize =stack->size*2;


    //allocate space for array

    array=(double*)malloc(STACK_INIT_SIZE *sizeof(double));

    //copy the data in previous array into a new one
    for(I=0;i<stack->size;i++)
    {
    array[i]=stack->elements[i];
    }
    FreeBlock(stack->elements);

    stack->elements=array;//but problem comes??
    //error C2106: '=' : left operand must be l-value

    stack->size=newSize;
    }

    I don't know why?




    This is my code:
    I want to creat a calculator

    #include <stdlib.h> /* For _MAX_PATH definition */
    #include <stdio.h>
    #include <malloc.h>
    #include <string.h>
    #include <simpio.h>
    #include <conio.h>


    #define STACK_INIT_SIZE 100
    #define STACKINCREMENT 10

    typedef double stackElementT;
    typedef struct {
    stackElementT elements[STACK_INIT_SIZE];
    int count;
    int size;
    }stackCDT;//抽象类型


    void ExpandStack(stackCDT* stack);
    void InitStack(stackCDT* stack);
    void Push(stackCDT* stack,stackElementT element);

    main()
    { stackCDT *OPTR,*OPND;
    char line[19];
    int theta;
    int a,b,c;
    int I;
    InitStack(OPTR);
    InitStack(OPND);

    }
    void InitStack(stackCDT* stack)
    {
    stackElementT *array;
    array=(double*)malloc(STACK_INIT_SIZE *sizeof(double));
    stack->elements=array;//(double*)malloc(STACK_INIT_SIZE *sizeof(double));
    stack->count=0;
    stack->size= STACK_INIT_SIZE;
    }


    void Push(stackCDT* stack,stackElementT element)
    {
    if(stack->count==stack->size)
    ExpandStack(stack);
    stack->elements[stack->count++]=element;
    }


    void ExpandStack(stackCDT* stack)
    {
    stackElementT *array;
    int I,newSize;

    newSize =stack->size*2;
    array=(double*)malloc(STACK_INIT_SIZE *sizeof(double));
    for(I=0;i<stack->size;i++)
    {
    array[i]=stack->elements[i];
    }
    FreeBlock(stack->elements);
    stack->elements=array;
    stack->size=newSize;
    }




    stackElementT Pop(stackCDT* stack)
    {
    if(StackIsEmpty(stack))
    Error("Pop of an empty stack");
    return (stack->elements[--stack->count]);

    }

Check out some similar questions!

Please help me out on formulating a linear programming model for this problem. [ 7 Answers ]

The Bluegrass Distillery produces custom-blended whiskey. A particular blen consists of rye and bourbon whiskey. The company has received an order for a minimum of 400 gallons of the custon blend. The customer specified that the order must contain at least 40% rye and not more than 250 gallons of...

Graph as a data structure. [ 1 Answers ]

How I can write a program for DFS/BFS using graph in C Programming ? Help; thanks in advance.

Data structure in c++ [ 1 Answers ]

Define:data hiding,encapsulation,inheritance,polymorphism,message passing,dyanamic binding.


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.