Skip to content

Commit 91e8c32

Browse files
committed
fix bugs
1 parent bd2976e commit 91e8c32

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

SLLst.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "SLLst.h"
2+
#include <iostream>
3+
4+
template <class T>
5+
SLLst<T>::~SLLst() {
6+
for (SLLstNode * p;!isEmpty();) {
7+
p=head->next;
8+
delet head;
9+
head=p;
10+
}
11+
}
12+
template <class T>
13+
SLLst<T>::addToHead(const T & el) {
14+
head=new SLLstNode(el,head);
15+
if(tail == 0)
16+
tail=head;
17+
}
18+
template <class T>
19+
T SLLst<T>::deletFromTail() {
20+
T el = tail->info;
21+
if (head == tail) {
22+
delete head;
23+
head =tail =0 ;
24+
}
25+
else {
26+
SLLstNode * tmp;
27+
for (tmp = head;tmp->next != tail ; tmp=tmp->next) ;
28+
delete tail;
29+
tail =tmp;
30+
tail->next = 0;
31+
}
32+
return el;
33+
}

0 commit comments

Comments
 (0)