1>d:\调试\数据结构实验二\数据结构实验二\数据结构实验二.cpp(123): fatal error C1075: 与左侧的 大括号“{”(位于“d:\调
// 数据结构实验二.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
template <class Type>class Stack
{
private:
int top;//顶层
Type *emements;//指向栈的指针
int MaxSize;//栈的大小
public:
Stack(int maxsize=20);
~Stack();
void InitStack();
void Push(const Type &item);//进栈
Type Pop(Stack<Type>&stack); //出栈
void MakeEmpty();//置空栈
void IsEmpty();//栈空
void IsFull();//栈满
Type GetTop(Stack<Type>&stack);//得到栈顶元素
};
template <class Type>Stack<Type>::Stack(int maxsize)
{
top=-1;
MaxSize=maxsize;
elements=new Type[MaxSize];
assert(elements!=0);//断言分配空间不为空
}
template <class Type>Stack<Type>::~Stack()
{
delete [] elements;
assert(elements=0);//断言分配空间为空,此时删除栈
}
template <class Type> void Stack<Type>::IsFull()
{
top=MaxSize-1;
}
template <class Type> void Stack<Type>::IsEmpty()
{
top=-1;
}
template <class Type> void Stack<Type>::MakeEmpty()
{
top=-1;
}
template <class Type> void Stack<Type>::Push ( const Type & item )
{
assert(!IsFull());//断言栈没满
element[++top]=item;//顶指针上移一位
}
template <class Type> Type Stack<Type>::Pop (Stack<Type>&stack)
{
assert(!stack.IsEmpty());//断言栈不为空
return element[top--]; //删除栈顶元素
}
template <class Type> Type stack<Type>::GetTop (Stack<Type>&stack )
{
assert ( !stack.IsEmpty () ); //先决条件断言
return elements[top]; //取出栈顶元素
}
template <class Type> void Stack<Type>::InitStack( )
{
for(int i=0;i<top;i++)
{
cin>>element[i];
}
}
#include <assert.h>//用assert命令断言
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int maxsize;
cout<<"栈的大小:";
cin>>maxsize;
cout<<endl;
Stack<int>stack(maxsize);
stack.InitStack();
cout<<"1,进栈 2,出栈 3,查看栈顶值 4,清空栈 5,退出"<<endl;
int operation;
cout<<"请输入操作:";
cin>>operation;
switch(operation)
{
case 1:
{
int item;
cout<<"输入进栈元素"<<endl;
stack.Push(item);
break;
}
case 2:
{
stack.Pop(stack);
break;
}
case 3:
{
stack.GetTop(stack);
break;
}
case 4:
{
stack.MakeEmpty();
break;
}
case 5:{
exit(1);
break;
}
default:
{
cout<<"输入错误!!!此程序将退出!!!"<<endl;
exit(0);
break;
}
}
}
//
#include "stdafx.h"
template <class Type>class Stack
{
private:
int top;//顶层
Type *emements;//指向栈的指针
int MaxSize;//栈的大小
public:
Stack(int maxsize=20);
~Stack();
void InitStack();
void Push(const Type &item);//进栈
Type Pop(Stack<Type>&stack); //出栈
void MakeEmpty();//置空栈
void IsEmpty();//栈空
void IsFull();//栈满
Type GetTop(Stack<Type>&stack);//得到栈顶元素
};
template <class Type>Stack<Type>::Stack(int maxsize)
{
top=-1;
MaxSize=maxsize;
elements=new Type[MaxSize];
assert(elements!=0);//断言分配空间不为空
}
template <class Type>Stack<Type>::~Stack()
{
delete [] elements;
assert(elements=0);//断言分配空间为空,此时删除栈
}
template <class Type> void Stack<Type>::IsFull()
{
top=MaxSize-1;
}
template <class Type> void Stack<Type>::IsEmpty()
{
top=-1;
}
template <class Type> void Stack<Type>::MakeEmpty()
{
top=-1;
}
template <class Type> void Stack<Type>::Push ( const Type & item )
{
assert(!IsFull());//断言栈没满
element[++top]=item;//顶指针上移一位
}
template <class Type> Type Stack<Type>::Pop (Stack<Type>&stack)
{
assert(!stack.IsEmpty());//断言栈不为空
return element[top--]; //删除栈顶元素
}
template <class Type> Type stack<Type>::GetTop (Stack<Type>&stack )
{
assert ( !stack.IsEmpty () ); //先决条件断言
return elements[top]; //取出栈顶元素
}
template <class Type> void Stack<Type>::InitStack( )
{
for(int i=0;i<top;i++)
{
cin>>element[i];
}
}
#include <assert.h>//用assert命令断言
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int maxsize;
cout<<"栈的大小:";
cin>>maxsize;
cout<<endl;
Stack<int>stack(maxsize);
stack.InitStack();
cout<<"1,进栈 2,出栈 3,查看栈顶值 4,清空栈 5,退出"<<endl;
int operation;
cout<<"请输入操作:";
cin>>operation;
switch(operation)
{
case 1:
{
int item;
cout<<"输入进栈元素"<<endl;
stack.Push(item);
break;
}
case 2:
{
stack.Pop(stack);
break;
}
case 3:
{
stack.GetTop(stack);
break;
}
case 4:
{
stack.MakeEmpty();
break;
}
case 5:{
exit(1);
break;
}
default:
{
cout<<"输入错误!!!此程序将退出!!!"<<endl;
exit(0);
break;
}
}
}
...全文
相关推荐
Visual+C+++中fatal+error+C1083的解决办法
### Visual C++ 中 fatal error C1083 的解决办法#### 症状与问题描述在使用 Visual C++ 进行开发时,开发者可能会遇到以下错误信息:```fatal error
fatal error C1083: 无法打开包括文件:“afxcontrolbars.h”
:“fatal error C1083: 无法打开包括文件:“afxcontrolbars.h””。
fatal error LNK1104: 无法打开文件“libc.lib”的解决方法
“libc.lib”是C运行时库的一部分,包含了C语言的基本函数,如内存分配、I/O操作等。在Windows平台上,它通常与较低版本的Visual C++或其他编译器关联。
fatal error C1083: 无法打开包括文件:“stdint.h”: No such file or directory
fatal error C1083: 无法打开包括文件:“stdint.h”: No such file or directory. stdint.h是c99标准的头文件,vc不支持,所以肯定会提示“
解决fatal error C1010 unexpected end of file while looking for precompiled header
当出现“fatal error C1010”时,可能有以下几个原因:1. **缺少#include指令**:最常见的情况是源代码文件中没有包含预编译头文件`#include "stdafx.h"`。


