zoukankan      html  css  js  c++  java
  • 变量的名字应当使用“名词”或者“形容词+名词”

    变量的名字应当使用“名词”或者“形容词+名词”。 例如: float value; float oldValue; float newValue;

     1 #include <iostream>
     2 
     3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */
     4 #define MAX 5
     5 //定义stack类接口
     6 using namespace std;
     7 class stack{
     8     int num[MAX];
     9     int top;
    10 public:
    11      stack(char *name);   //构造函数原型
    12     ~stack(void);         //析构函数原型
    13     void push(int n);
    14     int pop(void);
    15 };
    16 int main(int argc, char** argv) {
    17         int i,n;
    18     //声明对象
    19     stack a("a"),b("b");    
    20 
    21     //以下利用循环和push()成员函数将2,4,6,8,10依次入a栈
    22     for (i=1; i<=MAX; i++)
    23         a.push(2*i);
    24 
    25     //以下利用循环和pop()成员函数依次弹出a栈中的数据,并显示
    26     cout<<"a: ";
    27     for (i=1; i<=MAX; i++)
    28        cout<<a.pop()<<"  ";
    29     cout<<endl;
    30 
    31     //从键盘上为b栈输入数据,并显示
    32     for(i=1;i<=MAX;i++) {
    33         cout<<i<<" b:";
    34         cin>>n;
    35         b.push(n);
    36     }
    37     cout<<"b: ";
    38     for(i=1;i<=MAX;i++) 
    39        cout<<b.pop()<<" ";
    40     cout<<endl;
    41 
    42     return 0;
    43     
    44     return 0;
    45 }
    46 
    47 //-------------------------
    48 //   stack成员函数的定义
    49 //-------------------------
    50 //定义构造函数
    51 stack::stack(char *name)
    52 {
    53     top=0;
    54     cout << "Stack "<<name<<" initialized." << endl;
    55 }
    56 //定义析构函数
    57 stack::~stack(void)
    58 {
    59     cout << "stack destroyed." << endl;  //显示信息
    60 }
    61 //入栈成员函数
    62 void stack::push(int n)
    63 {
    64     if (top==MAX){
    65         cout<<"Stack is full !"<<endl;
    66         return;
    67     };
    68     num[top]=n;
    69     top++;
    70 }
    71 //出栈成员函数
    72 int stack::pop(void)
    73 {
    74     top--;
    75     if (top<0){
    76         cout<<"Stack is underflow !"<<endl;
    77         return 0;
    78     };
    79     return num[top];
    80 }
  • 相关阅读:
    redis运维的一些知识点
    nginx 实现Web应用程序的负载均衡
    JQuery中常用方法备忘
    高效程序猿之 VS2010快速生成代码模板
    C# var 隐式类型 var 用法 特点
    HTML之打开/另存为/打印/刷新/查看原文件等按钮的代码
    js函数大全(2)
    js常用函数大全107个
    js键盘键值大全
    js键盘键值大全
  • 原文地址:https://www.cnblogs.com/borter/p/9413410.html
Copyright © 2011-2022 走看看