forked from ChandanSitlani/Some-basic-Tricks-of-cp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate_class.cpp
57 lines (53 loc) · 957 Bytes
/
template_class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
using namespace std;
template<class T>
class List
{
T data;
List *next;
public:
List()
{
next=NULL;
}
void enter()
{
List<T>*start=this;
List<T>*node=new List<T>;
T d;
cout<<"\n enter the data: ";
cin>>d;
node->data=d;
node->next=NULL;
while(start->next!=NULL)
start=start->next;
start->next=node;
}
void display()
{
List<T>*start=this->next;
while(start!=NULL)
{
cout<<"\t"<<start->data;
start=start->next;
}
}
};
int main()
{
cout << "Hello world!" << endl;
List<int>l1;
int s,i;
cout<<"\n enter size of list";
cin>>s;
for(i=0;i<s;i++)
l1.enter();
l1.display();
List<float>l2;
cout<<"\n enter size of list";
cin>>s;
for(i=0;i<s;i++)
l2.enter();
l2.display();
return 0;
}