forked from drkencosh/listexercise2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.cpp
71 lines (69 loc) · 899 Bytes
/
list.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
#include <iostream>
#include "list.h"
using namespace std;
List::~List() {
for(Node *p; !isEmpty(); ) {
p=head->next;
delete head;
head = p;
}
}
void List::pushToHead(char el)
{
head = new Node(el, head, 0);
if(tail==0)
{
tail = head;
}
else
{
head->next->prev = head;
}
}
void List::pushToTail(char el)
{
//TO DO!
}
char List::popHead()
{
char el = head->data;
Node *tmp = head;
if(head == tail)
{
head = tail = 0;
}
else
{
head = head->next;
head->prev = 0;
}
delete tmp;
return el;
}
char List::popTail()
{
// TO DO!
return NULL;
}
bool List::search(char el)
{
// TO DO! (Function to return True or False depending if a character is in the list.
return NULL;
}
void List::print()
{
if(head == tail)
{
cout << head->data;
}
else
{
Node *tmp = head;
while(tmp!=tail)
{
cout << tmp->data;
tmp = tmp->next;
}
cout << tmp->data;
}
}