tochain.cpp

来自「数据结构c++语言描述 Borland C++实现」· C++ 代码 · 共 34 行

CPP
34
字号


#include<iostream.h>
#include "llist.h"
#include "echain.h"

template<class T>
void ArrayToChain(const LinearList<T>& L, Chain<T>& C)
{// Convert L to a chain C.
 // Do not catch exceptions that might be thrown.
   T x;
   C.Erase(); // empty the chain
   for (int i = L.Length(); i > 0; i--) {
      // copy i'th element of L
      L.Find(i,x);
      C.Insert(0,x);
      }
}

void main(void)
{
   int n = 15;
   LinearList<int> L(20);
   Chain<int> C;
   for (int i = 0; i < n; i++)
      L.Insert(0,i);
   cout << "The formula-based list is" << endl;
   cout << L << endl;

   ArrayToChain(L,C);
   cout << "The chain is" << endl;
   cout << C << endl;
}

⌨️ 快捷键说明

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