⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linklist.cpp

📁 小波图像编码中SPIHT算法的C++实现源码
💻 CPP
字号:
// LinkList.cpp: implementation of the CLinkList class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "LinkList.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLinkList::CLinkList()
{
	head = new ListElement;
	current = new ListElement;
	end = new ListElement;
	length = 0;
}

CLinkList::~CLinkList()
{
}

void CLinkList::Create()
{  
	head = NULL;
	current = NULL;
	end = NULL;
	length = 0;
}


void CLinkList::Append(ListType d)
{
	ListElement *p = (ListElement *) new ListElement;
  if (p!=NULL) {
    p->data = d;
    p->next = NULL;
	p->previous = end;
    if (end==NULL)
	{
		head = p;
		current = p;
		end = p;
	}
	else{
		 end->next = p;
         end = p;
	}
    length++;
  }
   else
	   ASSERT(false);
}

void CLinkList::Destroy()
{
	ListElement *p;
	
	p = head;
	/*while (p!=NULL) {
		head = p->next;
	    delete p;
		p = head;
	}*/
	head = NULL;
	current = NULL;
	end = NULL;
	length = 0;
}

void CLinkList::Reset()
{
	current = head;
}

CLinkList::ListType CLinkList::GetCurrentElement(char *found)
{
	if(current==NULL)
	{
		ASSERT(found);
	}
	else 
		*found = 1;
    return current->data;
	
}

void CLinkList::RemoveCurrentElement()
{
  ListElement *p;
  if (current==NULL){
	  ASSERT(false);
	  return;
  }
  else if(current==head){	
	  if(end==current){
		 delete current;
		 end = NULL;
		 current = NULL;
		 head = NULL;
	  }
	  else
	  {
		 head = head->next;
		 head->previous = NULL;
		 delete current;
		 current = head;
	  }
  }
  else{	
	 p = current->previous;
	 p->next = current->next;
	 delete current;
	 current = p->next;
	 if(current!=NULL)
		 current->previous = p;
	 else
		 end = p;
  }
  length--;

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -