Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<class Type>
- class cl
- {
- struct lis
- {
- lis* pre;
- lis* suc;
- Type a;
- } *first,*en;
- public:
- cl(const Type b)
- {
- lis *temp=new lis;
- temp->a=b;
- first=temp;
- en=temp;
- temp->pre=NULL;
- temp->suc=NULL;
- }
- void add(const Type b)
- {
- lis *temp = new lis;
- temp->a=b;
- temp->pre=en;
- en->suc=temp;
- temp->suc=NULL;
- en=temp;
- }
- void print()
- {
- lis *temp = first;
- do
- {
- cout << temp->a <<" ";
- temp=temp->suc;
- } while(temp);
- cout << '\n';
- }
- };
- int main ()
- {
- cl<int> a(1);
- a.add(2);a.add(3);
- a.print();
- cl<char> b('a');
- b.add('b');b.add('c');
- b.print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement