队列---旅行家算法

本文介绍了旅行家算法中遇到的常见问题及其解决方案,包括内存分配错误、输入输出格式问题以及如何正确使用`break`语句。同时,强调了`scanf`和`printf`的使用细节,帮助读者理解并避免编程过程中的常见陷阱。
摘要由CSDN通过智能技术生成

源代码:

  1 #include <stdlib.h> 
  2 #include <stdio.h> 
  3 
  4 #define MAX 100 
  5 #define C 5.9 
  6 #define N 5 
  7 
  8 #include <iostream> 
  9 using namespace std; 
 10 
 11 struct stationItem{ 
 12    int sn; 
 13    float cost; 
 14    float p; 
 15 }; 
 16 
 17 struct queue{ 
 18  stationItem *qe; 
 19  int front; 
 20  int tail; 
 21  int maxlen; 
 22 }; 
 23 
 24 int initQueue(struct queue *q,int max) 
 25 { 
 26   if(max < 0) 
 27   { 
 28    printf("max is invalid!\n"); 
 29    return -1; 
 30   } 
 31   q->maxlen = max; 
 32   q->qe = (stationItem *)malloc(max * sizeof(stationItem)); 
 33   if(!q->qe) 
 34   { 
 35    printf("Memory alloc error!\n"); 
 36    return -1; 
 37   } 
 38   q->front = q->tail = 0; 
 39   return 0; 
 40 } 
 41 
 42 int enQueue(struct queue *q,stationItem x) 
 43 { 
 44      if((q
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值