#include<iostream>
#include<string>
#include<windows.h>
using namespace std;
typedef struct list_node *list_pointer;
typedef struct list_node{
string data;
list_pointer link;
int x;
};
void red();
void white();
void green();
void yellow();
void blue();
int stations(list_pointer);
list_pointer add(list_pointer);
list_pointer del(list_pointer);
void calculate(list_pointer horhead,list_pointer verhead);
int main(void){
int select=1,total=2,addchoice,delchoice;
list_pointer verfirst,versecond,verthird,verforth,verlast,horfirst,horsecond,horthird,horforth,horlast;
verfirst=new list_node;
versecond=new list_node;
verthird=new list_node;
verforth=new list_node;
verlast=new list_node;
horfirst=new list_node;
horsecond=new list_node;
horthird=new list_node;
horforth=new list_node;
horlast=new list_node;
verfirst->data="善導寺";
versecond->data="忠孝新生";
verthird->data="忠孝復興";
verforth->data="忠孝敦化";
verlast->data="國父紀念館";
horfirst->data="中山國中";
horsecond->data="南京東路";
horthird->data="忠孝復興";
horforth->data="大安";
horlast->data="科技大樓";
verfirst->x=0;
versecond->x=0;
verthird->x=1;
verforth->x=0;
verlast->x=0;
horfirst->x=0;
horsecond->x=0;
horthird->x=1;
horforth->x=0;
horlast->x=0;
verfirst->link=versecond;
versecond->link=verthird;
verthird->link=verforth;
verforth->link=verlast;
verlast->link=NULL;
horfirst->link=horsecond;
horsecond->link=horthird;
horthird->link=horforth;
horforth->link=horlast;
horlast->link=NULL;
while(select!=0)
{
system("cls");
stations(verfirst);
stations(horfirst);
yellow();
cout << endl<<endl<<"*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*"<< endl<<endl;
white();
cout<< "\t(1)增加車站"<<endl<<"\t(2)刪除車站"<<endl<<"\t(3)計算起點到終點站數"<<endl<<"\t(0)預定車站確定" << endl<<"\t\t\t\t→";
cin >> select;
if(select==1)/*新增車站*/
{
cout<<"欲增加在(1)垂直線 或是(2)水平線 上車站:"<<endl;
cin>> addchoice;
switch(addchoice){
case 1:
add(verfirst);
stations(verfirst);
stations(horfirst);
break;
case 2:
add(horfirst);
stations(verfirst);
stations(horfirst);
break;
default:
cout<<"沒這個選項"<<endl;
break;
}
stations(verfirst);
stations(horfirst);
cout << endl << endl;
}
if(select==2)/*刪除車站*/
{
cout<<"欲刪除在(1)垂直線 或是(2)水平線 上車站:"<<endl;
cin>>delchoice;
switch(delchoice){
case 1:
verfirst=del(verfirst);
break;
case 2:
horfirst=del(horfirst);
break;
default:
cout<<"沒這個選項"<<endl;
break;
}
total=stations(verfirst)+stations(horfirst);
cout << endl << endl;
if(total==0)/*車站數=0*/
{
cout << "您已取消車站" << endl << endl;
system("pause");
}
}
if(select==3){/*計算車站數目*/
calculate(horfirst,verfirst);
}
}
if(select==0)/*確定車站*/
{
system("cls");
total=stations(verfirst)+stations(horfirst);
cout << endl << "一共有 " << total << " 站" << endl << endl << endl;
system("pause");
delete verfirst;
delete versecond;
delete verthird;
delete verforth;
delete verlast;
delete horfirst;
delete horsecond;
delete horthird;
delete horforth;
delete horlast;
}
return 0;
}
list_pointer add(list_pointer start){
int count;
list_pointer temp;
list_pointer next;
temp=start;
list_pointer newnode=new list_node;
cout << "新增在哪一站之後? (0)新增在最前面 " << endl;
cin >> count;
system("cls");
stations(start);
cout << endl << endl << "請輸入欲新增的站名: " << endl;
cin >>newnode->data;
if(count)
{
for(int i=0;i<count-1;i++)
{
if(temp->link==NULL)/*新增在最後面*/
{
temp->link =newnode;
newnode= NULL;
delete newnode;
return start;
}
temp = temp->link;
}
next = temp->link;
newnode->link = next;
temp->link = newnode;
newnode = NULL;
delete newnode;
return start;
}
else/*新增在最前面*/
{
newnode->link = start;
start = newnode;
newnode = NULL;
delete newnode;
return start;
}
}
list_pointer del(list_pointer start)
{
/*if(temp->x==0){*/
int count;
list_pointer temp = start;
list_pointer next;
list_pointer middle;
cout << "取消第幾站?" << endl;
cin >> count;
system("cls");
if(count-1)
{
for(int i=0;i<count-2;i++)
{
if(temp->link->link==NULL)/*取消最後一站*/
{
middle=temp->link;
middle = NULL;
delete middle;
return start;
}
temp = temp->link;
}
if(temp->link)/*車站數大於一*/
{
next = temp->link;
temp->link = next->link;
next->link = NULL;
return start;
}
else/*只有一站*/
{
start = NULL;
return start;
}
}
else/*取消第一站*/
{
start = temp->link;
temp->link = NULL;
return start;
}
/*}
else{
cout<<"交叉站刪了就不交叉了唷~"<<endl;
system("pause");
return start;}*/
}
int stations(list_pointer begin)
{
if(begin)/*車站數不為一*/
{
int count = 1;
list_pointer temp;
temp = begin;
cout <<endl<< "預定車站設置: " << endl;
while(temp->link)
{
cout << "(" << count << ")" << temp->data << " → ";
temp = temp->link;
count++;
}
cout << "(" << count << ")" << temp->data;
return count;
}
else/*沒有車站*/
{
int count = 0;
cout <<endl<< "預訂車站設置: " << endl;
return count;
}
}
void calculate(list_pointer horhead,list_pointer verhead)
{
int a=0,b=0,hor,ver,verst,count;
list_pointer temp1,temp2;
temp1=new list_node;
temp2=new list_node;
temp1=horhead;
for(;horhead;horhead=horhead->link){
a=a+1;
if(horhead->x==1){
没有合适的资源?快使用搜索试试~ 我知道了~
link_list(part-two).rar_How To Two

共1个文件
cpp:1个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
6 浏览量
2022-09-14
18:31:55
上传
评论
收藏 2KB RAR 举报
example of linklist, written with DevC++. It is a very simple demostration of how to use link list in C++.
资源推荐
资源详情
资源评论























收起资源包目录


共 1 条
- 1
资源评论

Kinonoyomeo
- 粉丝: 18
- 资源: 1万+

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制
