-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSLLst.cpp
More file actions
58 lines (57 loc) · 1.09 KB
/
Copy pathSLLst.cpp
File metadata and controls
58 lines (57 loc) · 1.09 KB
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
#include "SLLst.h"
#include <iostream>
template <class T>
SLLst<T>::~SLLst() {
for (SLLstNode<T> * p;!isEmpty();) {
p=head->next;
delete head;
head=p;
}
}
template <class T>
void SLLst<T>::addToHead(const T & el) {
head=new SLLstNode<T>(el,head);
if(tail == 0)
tail=head;
}
template <class T>
void SLLst<T>::addToTail (const T & el){
if(tail!=0){
tail->next=new SLLstNode<T>(el,0);
tail=tail->next;
}
else
head=tail=new SLLstNode<T>(el);
}
template <class T>
T SLLst<T>::deletFromHead() {
T el= head->info;
SLLstNode<T> * tmp =head;
if (head==tail)
head=tail=0;
else
head=head->next;
delete tmp;
return el;
}
template <class T>
T SLLst<T>::deletFromTail() {
T el = tail->info;
if (head == tail) {
delete head;
head =tail =0 ;
}
else {
SLLstNode<T> * tmp;
for (tmp = head;tmp->next != tail ; tmp=tmp->next) ;
delete tail;
tail =tmp;
tail->next = 0;
}
return el;
}
template <class T>
bool SLLst<T>::isInList(const T & el) const {
for (SLLstNode<T> * tmp = head;tmp!=tail && !(tmp->info==el);tmp=tmp->next) ;
return tmp !=0;
}