-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignleListImplimentation.cpp
135 lines (118 loc) · 2.17 KB
/
signleListImplimentation.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//implimentation of singley linked list
class node
{
public:
int value;
node* next;
node(int val,node* n=0)
{
value = val;
next = n;
}
};
class list
{
private:
node* head = 0;
node* tail = 0;
public:
node* getHead() { return head; }
node* getTail() { return tail; }
list();
list(int value);
list(int array[],int size);
list(int size,int value);
~list();
list(const list& rhs)
{
operator=(rhs);
}
const list& operator=(const list& rhs)
{
node* ohead = rhs.head;
distroy();
while(ohead!=0)
{
append_tail(ohead->value);
ohead = ohead->next;
}
return *this;
}
void append_head(int value);
void append_tail(int value);
void fill_random(int size = 5);
void distroy();
void print();
void reverse(list& tempHead,node* head);
};
list::~list()
{
distroy();
}
list::list()
{
head = 0;
tail = 0;
}
list::list(int value)
{
append_head(value);
}
list::list(int array[],int size)
{
for(int i=0;i<size;i++)
{
append_tail(array[i]);
}
}
list::list(int size,int value)
{
for(int i=0;i<size;i++)
{
append_tail(value);
}
}
void list::append_head(int value)
{
if(head ==0)
head = tail = new node(value);
else
head = new node(value,head);
}
void list::append_tail(int value)
{
if(tail==0)
head = tail = new node(value);
else{
tail->next = new node(value);
tail = tail->next;
}
}
void list::fill_random(int size)
{
list::distroy();
srand(time(0));
for(int i = 0; i<size;i++)
list::append_head(rand()%100);
}
void list::print()
{
node* temp = head;
while(temp != 0)
{
cout<<temp->value<<"-->";
temp = temp->next;
}
cout<<"//"<<endl;
}
void list::distroy()
{
while(head!= 0)
{
node* temp = head;
head = head->next;
delete temp;
}
head = 0;
tail = 0;
}