www.pudn.com > GraphCut.zip > LinkedBlockList.cpp
// LinkedBlockList.cpp: implementation of the LinkedBlockList class. // ////////////////////////////////////////////////////////////////////// #include "stdafx.h" #include "GraphCut.h" #include#include #include "LinkedBlockList.h" #ifdef _DEBUG #undef THIS_FILE static char THIS_FILE[]=__FILE__; #define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// LinkedBlockList::LinkedBlockList() { m_head = 0; m_head_block_size = GCLL_BLOCK_SIZE; } LinkedBlockList::~LinkedBlockList() { LLBlock *tmp; while ( m_head != 0 ) { tmp = m_head; m_head = m_head->m_next; delete tmp; } } /*********************************************************************/ 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); }