不会做,乱写的
#include <iostream> using namespace std; const int Max=10; template <class T> struct STree { T data[Max]; }; template <class T> class Tree { private: int length; STree<T> tree[Max]; public: Tree(); ~Tree(){} void put(); void print(); }; template <class T> Tree<T>::Tree() { length=0; } template <class T> void Tree<T>::put() { int i=0; cout<<"输入@为空,输入#结束"<<endl; for(;i<Max;i++) { if(tree[i].data!=NULL) { cout<<"输入第"<<i+1<<"个数:"; cin>>tree[i].data; } if(tree[i].data[0]=='#') { cout<<"结束输入!"<<endl; length=i; i=Max; } if(tree[i].data[0]=='@') { tree[i].data[0]='^'; } } } template <class T> void Tree<T>::print() { int i=0; for(;i<length;i++) {cout<<"第"<<i+1<<"个数"<<tree[i].data<<endl;} } int main() { Tree<char> a; a.put(); a.print(); return 0; }原文链接:https://www.f2er.com/datastructure/382815.html