main.cpp

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

CPP
47
字号
 
#include   "../../C/UTILITY.H"
#include   "LIST.H"
#include   "LIST.CPP"
 
void write_entry(char &c)
{
   cout << c;
}
 

main()
{
   char x;
   List<char> c_list;  //  a list of characters, initialized empty

   cout << "List is empty, it has " << c_list.size() << " items.\n";
   cout << "Enter characters and the program adds them to the list.\n";
   cout << "Use Enter key (newline) to terminate the input.\n";
   cout << "When ListSize() is 3, the element will be inserted at the ";
   cout << "front of the list.\n The others will appear at the back.\n";
   while (!c_list.full() && (x = cin.get()) != '\n')
      if (c_list.size() == 3) c_list.insert(0, x);
      else c_list.insert(c_list.size(), x);
   cout << "The list has " << c_list.size() << " items.\n";
   cout << "The function c_list.full(), got " << c_list.full();
   if (c_list.full()) cout << " because the list is full.\n";
   else cout << " because the list is NOT full.\n";
   cout << "c_list.empty(), expecting 0, got " << c_list.empty() << ".\n";
   cout << "c_list.traverse(write_entry) output:  ";
   c_list.traverse(write_entry);
   cout << "\n";
   c_list.clear();
   cout << "Cleared the list, printing its contents:\n";
   c_list.traverse(write_entry);
   cout << "\n";
   cout << "Enter characters and the program adds them to the list.\n";
   cout << "Use Enter key (newline) to terminate the input.\n";
   cout << "When ListSize() is < 3, the element will be inserted at the ";
   cout << "front of the list.\n The others will appear at the back.\n";
   while (!c_list.full() && (x = cin.get()) != '\n')
      if (c_list.size() < 3) c_list.insert(0, x);
      else c_list.insert(c_list.size(), x);
   c_list.traverse(write_entry);
   cout << "\n";
}

⌨️ 快捷键说明

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