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

📄 traffic_info.cpp

📁 (1) 提供对城市信息进行编辑(添加或删除)的功能.(2) 城市之间有两种交通工具:火车和飞机.提供对列车时刻表和飞机航班进行编辑(增设或删除)的功能.(3) 提供两种最优策略:最快到达或最省钱到达.
💻 CPP
字号:
#include "Traffic.h"

Traffic_Info::Traffic_Info(int start,double cost,double fee)
{
	m_start=start;
	m_cost=cost;
	m_fee=fee;
	m_next=NULL;
}

int Traffic_Info::m_GetStart()
{
	return m_start;
}

double Traffic_Info::m_GetCost()
{
	return m_cost;
}

double Traffic_Info::m_GetFee()
{
	return m_fee;
}

void Traffic_Info::m_SetStart(int new_start)
{
	m_start=new_start;
}

void Traffic_Info::m_SetCost(double new_cost)
{
	m_cost=new_cost;
}

void Traffic_Info::m_SetFee(double new_fee)
{
	m_fee=new_fee;
}

void Traffic_Info::m_SetNext(t_info p)
{
	m_next=p;
}

t_info Traffic_Info::m_Successor()
{
	return m_next;
}
/////////////////////////////////////Traffic_Info类定义结束///////////////////////////////////////

/////////////////////////////////////Traffic_Table类//////////////////////////////////////////////
Traffic_Table::Traffic_Table()
{
	head=new Traffic_Info(0,0,0);
	head->m_SetNext(NULL);
	size=0;
}

Traffic_Table::Traffic_Table(Traffic_Table& other)//等待InsertTable函数
{
	t_info p,q;
	size=other.size;
	head=new Traffic_Info(0,0,0);
	head->m_SetNext(NULL);
	for(p=other.GetHead()->m_Successor();p;p=p->m_Successor())
	{
		q=new Traffic_Info(p->m_GetStart(),p->m_GetCost(),p->m_GetFee());
		InsertTable(q);
	}
}

Traffic_Table::~Traffic_Table()
{
	t_info p=head,temp;
	while(p)
	{
		temp=p;
		p=p->m_Successor();
		delete temp;
	}
}

int Traffic_Table::GetSize()
{
	return size;
}

t_info Traffic_Table::GetHead()
{
	return head;
}


////////////////创建邻接表
void Traffic_Table::InsertTable(t_info p)///将数据输入到邻接表
{
	t_info q,pre,temp;
	for(pre=head,q=head->m_Successor();q && q->m_GetStart()< p->m_GetStart() ;  )
	{
		pre=q;
		q=q->m_Successor();////类似q=q->next,即指向下一个表结点
	}
	temp=pre->m_Successor();
	pre->m_SetNext(p);
	p->m_SetNext(temp);
	size++;//// size为邻接表的长度
}

void Traffic_Table::DeleteTable(t_info p)//认为不会删错
{
	t_info q,pre,temp;
	for(pre=head,q=head->m_Successor();q && q->m_GetStart()!=p->m_GetStart();pre=q,q=q->m_Successor());
	temp=p->m_Successor();
	pre->m_SetNext(temp);
	p->m_SetNext(NULL);
	delete p;
	size--;
}

t_info Traffic_Table::LocateTraffic(int stime)//找不到就返回NULL
{
	t_info p;
	for(p=head;p;p=p->m_Successor())
		if(p->m_GetStart()==stime)
			break;
	return p;
}

void Traffic_Table::ShowTable()
{
	t_info p;
	for(p=head->m_Successor();p;p=p->m_Successor())
		cout<<"出发时间:"<<p->m_GetStart()<<" 费用:"<<p->m_GetFee()<<endl;
}

⌨️ 快捷键说明

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