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

📄 list1.cpp

📁 虚基类的实现
💻 CPP
字号:
// list1.cpp: implementation of the list class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "list1.h"
#include "Node.h"
#include<iostream>
using namespace std; 
//#include "Object.h"

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

list::list()
{
	head=tail=new Node();

}

list::~list()
{
	MakeEmpty();
	cout<<"删除头结点"<<'t';
    delete head;
}

void list::MakeEmpty()
{
	Node *tempP;
	while(head->getlink()!=NULL)
	{
		tempP=head->getlink();
		head->setlink(tempP->getlink());
		delete tempP;
	}
	tail=head;

}

Node * list::Find(Object &obj)
{
	Node *tempP=head->getlink();
	while(tempP!=NULL&&*tempP->getinfo()!=obj)
		tempP=tempP->getlink();
	return tempP;

}

int list::Length()
{
	Node *tempP=head->getlink();
	int count=0;
	while(tempP!=NULL)
	{
		tempP=tempP->getlink();
		count++;
	}
	return count;

}

void list::InsertFront(Node *p)
{
	
	p->setlink(head->getlink());
	head->setlink(p);
	if(tail=head)
		tail=p;


}

void list::InsertRear(Node *p)
{
	p->setlink(tail->getlink());
	tail->setlink(p);
	tail=p;

}

void list::InsertOrder(Node *p)
{
	Node *tempP=head->getlink(),*tempQ=head;
	while(tempP!=NULL)
	{
		if(*(tempP->getinfo())>*(p->getinfo()))
			break;
		tempQ=tempP;
		tempP=tempP->getlink();
	}
	tempQ->InsertAfter(p);
	if(tail==tempQ)
		tail=tempQ->getlink();

}

Node * list::CreatNode()
{
	Node *tempP=new Node();
	return tempP;

}

Node * list::DeleteNode(Node *p)
{
	Node *tempP=head;
	while(tempP->getlink()!=NULL&&tempP->getlink()!=p)
		tempP=tempP->getlink();
	return tempP->RemoveAfter();

}

void list::PrintList()
{
	Node *tempP=head->getlink();
	while(tempP!=NULL)
	{
	tempP->getinfo()->Print();
	tempP=tempP->getlink();
	}
	cout<<endl;

}

⌨️ 快捷键说明

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