65,202
社区成员




#include "stdafx.h"
#include "targetver.h"
#include <iostream>
using namespace std;
template <class T> class Telist
{
public:
Telist();
int counter;
void put(T&);
T* get(int);
void print();
~Telist();
protected:
struct Node
{
Node *next;
T *pt;
};
Node *first;
Node *first2;
};
template <class T> void Telist<T>::put(T &e)
{
Node *temp = new Node;
if(!first)
{
first->pt=&e;
first->next=NULL;
first2=first;
counter++;
}else
{
temp->pt= &e;
temp->next=NULL;
first2->next=temp;
first2=temp;
counter++;
}
}
template <class T> T* Telist<T>::get(int x)
{
for(int i=0;i<x;i++)
{
p=p->next;
}
return *(p->pt);
}
template <class T>void Telist<T>:: print()
{
for(Node *p=first;p;p=p->next)
{
cout<<*(p->pt)<<"--";
}
cout<<endl;
}
#include "stdafx.h"
#include"TList.h"
#include<iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
Telist<int> L;
for(int i=0;i<10;i++)
{
L.put(i);
}
L.print();
return 0;
}