main.cpp

来自「数据结构与程序设计教材源码 数据结构与程序设计教材源码」· C++ 代码 · 共 41 行

CPP
41
字号
 
#include   "../../C/UTILITY.H"
 
typedef float Stack_entry;  //  The program will use stacks with float entries.
#include   "STACK.H"
 
#include   "../../C/UTILITY.CPP"
#include   "STACK.CPP"
 
main()
/*   
Pre:    The user supplies an integer n and n
floating point numbers.
Post:  The floating point numbers are printed in reverse order.
Uses:  The class Stack and its methods
 */

{
   int n;
   float item;
   Stack numbers;

   cout << " Type in an integer n followed by n floating point numbers.\n"
        << " The numbers will be printed in reverse order." << endl;
   cin  >> n;

   for (int i = 0; i < n; i++) {
      cin >> item;
      if (numbers.push(item) == overflow)
         cout << "\nThe stack is full." << endl;
   }

   cout << "\n\n";
   while (!numbers.empty()) {
      numbers.top(item);
      numbers.pop();
      cout << item << " ";
   }
   cout << endl;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?