#include<iostream> using namespace std; #define LEN 50 typedef struct stations{ char name[20]; int len; int roads[50]; struct stations *left ; struct stations *right ; }Stations; typedef struct etree{ int value; int roadNum; struct etree *father; int childnum; }ETree; typedef struct queue{ ETree *tie; struct queue *next; }Queue; void pushQueue(Queue &head , ETree *&etree){ Queue *p = head.next , *q = &head ; while( p!=NULL && (p->tie->value < etree->value) ){ q = p ; p = p->next ; } q->next = (Queue*)malloc(sizeof(Queue)) ; q->next->tie = etree ; q->next->next = p ; } void freeEtree(ETree *q){ ETree *p; while(q->childnum==0){ p = q; q = q->father; free(p); if(q!=NULL) q->childnum--; else break; } } void freeAll(Stations * &head){ if(head!=NULL){ freeAll(head->left); freeAll(head->right); free(head); } } void showBest(ETree *h,int price[][LEN],char roadName[][20],int roadNum){ if(h!=NULL){ if(h->father==NULL){ printf("%s",roadName[h->roadNum]); } else{ int j; j = h->roadNum ; if( h->value == ( price[j][j] + h->father->value ) ){ showBest(h->father,price,roadName,roadNum); if(price[j][roadNum]){ printf("-(%s,%s)",roadName[j],roadName[price[j][roadNum]-1]); } else printf("-%s",roadName[j]); } else{ showBest(h->father->father,price,roadName,roadNum); printf("-(%s,%s)",roadName[h->father->roadNum],roadName[j]); } } } } inline int compares(char s1[],int n1 , char s2[] ,int n2){ if(n1!=n2) return n1-n2; return strcmp(s1,s2); } bool findStation(Stations* &head , Stations* &p , char s[]){ int len = strlen(s); int t; Stations *q; p=head; while(p!=NULL){ q = p; t=compares(s,len,p->name,p->len); if(t<0) p=p->left; else if(t>0) p=p->right; else return true; } p = q; return false; } void insert(Stations* &head,char s[] , int road,int price[][LEN]){ Stations *p,*q; int t; t=strlen(s); if(s[t-1]==' ') s[t-1] = '