堆栈概念中有错误

时间:2018-08-13 15:27:11

标签: c++ c++11 visual-c++ c++14 dev-c++

    #include <iostream>
using namespace std;

struct ArrayStack
{
    int top;
    int capacity;
    int *array;
};

 ArrayStack* createStack(int cap)
{
    ArrayStack *stack=new ArrayStack();
    stack->capacity=cap;
    stack->array= new int[stack->capacity];
    return stack;
}
int isFull(ArrayStack *stack)
{
    if(stack->top>=stack->capacity-1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
int isEmpty(ArrayStack *stack)
{
    if(stack->top<0)
    {
        return 1;
    }
    else
    {
        return 0; 
    }
}

void push(ArrayStack *stack, int item)
{
    if(!isFull(stack))
    {
        stack->top += 1;
        stack->array[stack->top]=item;
    }
    else
    {
        cout<<"Sorry Stack is Full ! iteam cannot be store"<<endl;
    }
}
int pop(ArrayStack *stack)
{
    int item;
    if(isEmpty(stack))
    {
        cout<<"Sorry stack is Empty"<<endl;
        return -1;
    }
    else
    {
        item=stack->array[stack->top];
        stack->top--;
        return item;
    }
}

int main()
{

    return 0;
}

我在Dev-C ++中遇到此错误: $(CPP)$(LINKOBJ)-o $(BIN)$(LIBS)

,在Visual Studio中,我遇到此错误:

错误3错误LNK1169:找到一个或多个乘法定义的符号H:\ study \ programs \ data_structure \ Data_struchers_inC ++ \ Debug \ Data_struchers_inC ++。exe 1 1 Data_struchers_inC ++

1 个答案:

答案 0 :(得分:1)

您发布的代码可以正常编译,包含的头文件中已经存在probalby变量或结构。尝试使用std::stack很好地实现这一概念。