-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
LinkedList.cpp
111 lines (77 loc) · 1.32 KB
/
LinkedList.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#include<iostream>
using namespace std;
class node{
public:
int data;
node*next;
node(int d){
data=d;
next=NULL;
}
};
class linkedList{
node*head;
node*tail;
public:
// Constructor
linkedList(){
head=NULL;
tail=NULL;
}
// Copy Constructor
linkedList(linkedList &l){
cout<<"Copy Constructor Called"<<endl;
head=l.head;
tail=l.tail;
}
// Copy Assignment Operator
void operator = (linkedList l){
cout<<"Copy Assignment operator Called"<<endl;
head=l.head;
tail=l.tail;
}
void insertInLL(int d){
if(head==NULL){
node*n=new node(d);
head=tail=n;
}else{
node*n=new node(d);
tail->next=n;
tail=n;
}
}
void print(){
node*temp=head;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
// Destructor
~linkedList(){
cout<<"Destroying the LinkedList"<<endl;
}
};
int main(){
node a(1);
node b(2);
node *p=&a;
a.next=&b;
// use of arrow operator
cout<<((*a.next).data)<<endl;
cout<<a.next->data<<endl;
cout<<p->data<<endl;
linkedList l;
l.insertInLL(1);
l.insertInLL(2);
l.insertInLL(3);
l.insertInLL(4);
l.insertInLL(5);
l.insertInLL(6);
l.insertInLL(7);
l.print();
linkedList m;
m=l;
return 0;
}