#include <iostream>
#include <string>
using namespace std;
template<class Type>
class link
{
public:
Type num;
link *next;
private:
};
//创建
template<class Type>
link<Type> *init()
{
link<Type> *a = new link<Type>;
if(a==NULL)
{
cout<<"空间开辟失败!"<<endl;
return 0;
}
a->num = 0;
a->next = NULL;
return a;
}
//增添
template<class Type >
void Add(link<Type> *a)
{
//判断
if (a == NULL)
{
cout << "插入失败" << endl;
return;
}
else
{
for (int i = 1; i < 10; i++)
{
link<Type>*b = init<Type>();
b->num = i;
b->next = a->next;
a->next = b;
}
}
}
//打印
template<class Type >
void drow(link<Type>*a)
{
link<Type>*temp = a;
temp = temp->next;
while (temp)
{
cout << temp->num << " ";
temp =
c++日常练习(5、模板)
于 2022-02-09 22:51:18 首次发布