#include "stdio.h"
#include "stdlib.h"
struct stack
{
int data;
struct stack *next;
};
typedef struct stack stack;
typedef stack *link;
link pointer = NULL;
void printStack();
void push(int value);
int pop(); //返回值等于1,则堆栈中没有元素。否则,返回堆栈顶端元素
int main()
{
int value;
enum choose { push, pop, print, quit } choice; //存放--0,取出--1,打印--2,退出--3
printf("push is 0, pop is 1, print is 2, quit is 3. please select one choice : ");
scanf("%d",&choice);
do{
switch(choice)
{
case 0:
printf("Input a value : ");
scanf("%d",&value);
push(value);
break;
case 1:
value = pop();
if(value == -1)
printf("Have not data!\n");
else
printf("The data is : %d \n",value);
break;
case 2:
printStack();
break;
default:
break;
}
printf("push is 0, pop is 1, print is 2, quit is 3. please select one choice : ");
scanf("%d",&choice);
}while(choice != 3);
return 0;
}
void printStack()
{
link head;
head = pointer;
printf("Output the stack data :\n");
while(head != NULL)
{
printf("%d/t",head->data);
head = head->next;
}
printf("\n");
}
void push(int value)
{
link top = NULL;
top = (link)malloc(sizeof(stack));
if(top == NULL)
printf("memory allocate failure!\n");
else
{
top->data = value;
top->next = pointer;
pointer = top;
}
}
int pop()
{
int temp;
link top;
top = pointer;
if(top != NULL)
{
temp = pointer->data;
pointer = pointer->next;
free(top);
return temp;
}
return -1;
}
错误信息:C:\Program Files\Microsoft Visual Studio\MyProject\tt\a.cpp(29) : error C2064: term does not evaluate to a function
C:\Program Files\Microsoft Visual Studio\MyProject\tt\a.cpp(32) : error C2064: term does not evaluate to a function
执行 cl.exe 时出错.
请高手帮我找出错误 急急急