-
Notifications
You must be signed in to change notification settings - Fork 31
/
LinkedBlockList.cpp
67 lines (51 loc) · 1.35 KB
/
LinkedBlockList.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
#include "LinkedBlockList.h"
#include <stdio.h>
#include <stdlib.h>
/*********************************************************************/
void LinkedBlockList::addFront(ListType item) {
if ( m_head_block_size == GCLL_BLOCK_SIZE )
{
LLBlock *tmp = (LLBlock *) new LLBlock;
if ( !tmp ) {printf("\nOut of memory");exit(1);}
tmp -> m_next = m_head;
m_head = tmp;
m_head_block_size = 0;
}
m_head ->m_item[m_head_block_size] = item;
m_head_block_size++;
}
/*********************************************************************/
ListType LinkedBlockList::next()
{
ListType toReturn = m_cursor -> m_item[m_cursor_ind];
m_cursor_ind++;
if ( m_cursor == m_head && m_cursor_ind >= m_head_block_size )
{
m_cursor = m_cursor ->m_next;
m_cursor_ind = 0;
}
else if ( m_cursor_ind == GCLL_BLOCK_SIZE )
{
m_cursor = m_cursor ->m_next;
m_cursor_ind = 0;
}
return(toReturn);
}
/*********************************************************************/
bool LinkedBlockList::hasNext()
{
if ( m_cursor != 0 ) return (true);
else return(false);
}
/*********************************************************************/
LinkedBlockList::~LinkedBlockList()
{
LLBlock *tmp;
while ( m_head != 0 )
{
tmp = m_head;
m_head = m_head->m_next;
delete tmp;
}
};
/*********************************************************************/