输出有问题,请高手看看是哪里的问题
时间:2011-12-07
来源:互联网
#include<iostream>
using namespace std;
const int MAXSIZE=5;
struct datatype
{
char name[10],author[10],publish[20];
float price;
};
class Stack
{
private:
datatype data[MAXSIZE];
int top;
public:
Stack();
int Push_SeqStack(datatype x);
int Pop_SeqStack();
void Print_SeqStack();
};
Stack::Stack()
{
top=0;
}
int Stack::Push_SeqStack(datatype x)
{
strcpy(data[top].name,x.name);
strcpy(data[top].author,x.author);
strcpy(data[top].publish,x.publish);
data[top].price=x.price;
top++;
return top;
}
int Stack::Pop_SeqStack()
{
if(top==0)
{
cout<<"Stack is empty.";
return 0;
}
top--;
return top;
}
void Stack::Print_SeqStack()
{
for(int i=0;i<top;i++)
cout<<data[top].name<<endl<<data[top].author<<endl<<data[top].publish<<endl<<data[top].price<<endl;
}
int main()
{
Stack s;
struct datatype x;
strcpy(x.name,"数据结构");
strcpy(x.author,"严蔚敏");
strcpy(x.publish,"清华大学出版社");
x.price=30.00;
s.Push_SeqStack(x);
s.Print_SeqStack();
}
using namespace std;
const int MAXSIZE=5;
struct datatype
{
char name[10],author[10],publish[20];
float price;
};
class Stack
{
private:
datatype data[MAXSIZE];
int top;
public:
Stack();
int Push_SeqStack(datatype x);
int Pop_SeqStack();
void Print_SeqStack();
};
Stack::Stack()
{
top=0;
}
int Stack::Push_SeqStack(datatype x)
{
strcpy(data[top].name,x.name);
strcpy(data[top].author,x.author);
strcpy(data[top].publish,x.publish);
data[top].price=x.price;
top++;
return top;
}
int Stack::Pop_SeqStack()
{
if(top==0)
{
cout<<"Stack is empty.";
return 0;
}
top--;
return top;
}
void Stack::Print_SeqStack()
{
for(int i=0;i<top;i++)
cout<<data[top].name<<endl<<data[top].author<<endl<<data[top].publish<<endl<<data[top].price<<endl;
}
int main()
{
Stack s;
struct datatype x;
strcpy(x.name,"数据结构");
strcpy(x.author,"严蔚敏");
strcpy(x.publish,"清华大学出版社");
x.price=30.00;
s.Push_SeqStack(x);
s.Print_SeqStack();
}
作者: a18451175 发布时间: 2011-12-07
C/C++ code
#include<iostream> using namespace std; const int MAXSIZE=5; struct datatype { char name[10],author[10],publish[20]; float price; }; class Stack { private: datatype data[MAXSIZE]; int top; public: Stack(); void Push_SeqStack(datatype x); int Pop_SeqStack(); void Print_SeqStack(); }; Stack::Stack() { top=0; } void Stack::Push_SeqStack(datatype x) { strcpy(data[top].name,x.name); strcpy(data[top].author,x.author); strcpy(data[top].publish,x.publish); data[top].price=x.price; // top++; // return top; } int Stack::Pop_SeqStack() { if(top==0) { cout<<"Stack is empty."; return 0; } top--; return top; } void Stack::Print_SeqStack() { for(int i=0;i<top;i++) ; // 老大 下标为 i 不是top cout<<data[i].name<<endl<<data[i].author<<endl<<data[i].publish<<endl<<data[i].price<<endl; } int main() { Stack s; struct datatype x; strcpy(x.name,"数据结构"); strcpy(x.author,"严蔚敏"); strcpy(x.publish,"清华大学出版社"); x.price=30.00; s.Push_SeqStack(x); s.Print_SeqStack(); }
作者: yuegeman 发布时间: 2011-12-07
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28