list.cpp
533 Bytes
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
#include <iostream>
using namespace std;
#include "list.h"
list::list()
{
head = NULL;
current = NULL;
}
list::~list()
{
while(head)
{
node* t=head->next;
delete head;
head=t;
};
}
void list::insert(int a)
{
node* t=new node;
t->next=head;
head = t;
head->val = a;
}
void list::goToHead()
{
current=head;
}
int list::getCurrentData()
{
return current->val;
}
void list::advance()
{
current=current->next;
}
bool list::moreData()
{
if(current)
return true;
else
return false;
}