CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

堆栈问题

楼主lcrystal623(小水晶)2005-08-08 11:37:17 在 VC/MFC / 基础类 提问

在数据库的表中有这样两列,第一列是一条线路的起点,第二列是该线路的终点,而下一项记录的起点可能是刚才那线路的终点,同时一个起点可能有不同终点,会在表中有多条记录。要求是从数据库中读数据,将线路记录到文件中。  
  我是这样考虑的,用深度优先,先将起点入栈,然后在数据库中找到起点可到的终点,再将他们入栈,只要栈不空,就pop,然后再搜索pop出的点的终点。数据库中起点,终点类似:1-1-2station,1-1-3pole等,所以要用CString,堆栈是这样的:  
  #include<malloc.h>  
  #include<windows.h>  
   
  struct   Stack  
  {  
  CString   *   top;  
  CString   *   bottom;  
  };  
   
  void   initStack(Stack   *   s)  
  {  
  s->bottom   =   (CString   *)malloc(2000   *   sizeof(CString));  
  s->top   =   s->bottom;  
  }  
   
  void   push(Stack   *   s,CString   &path,CString   &name)  
  {  
  if((s->top   -   s->bottom)   <   2000)  
  {  
  *(s->top)   =   path;  
  (s->top)++;  
  *(s->top)   =   name;  
  (s->top)++;  
  }  
  else  
  AfxMessageBox("堆栈已满!");  
  }  
   
  void   pop(Stack   *   s,CString   &name,CString   &path)  
  {  
  if((s->top   -   s->bottom)   >   0)  
  {  
  s->top--;  
  name   =   *(s->top);  
  s->top--;  
  path   =   *(s->top);  
  }  
  else  
  AfxMessageBox("堆栈已空!");  
  }  
   
  bool   isEmpty(Stack   *   s)  
  {  
  if(s->top   ==   s->bottom)  
  return   true;  
  else  
  return   false;  
  }  
   
  引用是这样的:  
  Stack   *   s   =   (Stack   *)malloc(sizeof(Stack));  
  bool   flag   =   false;  
  initStack(s);  
   
  SQLRETURN   rc;  
  CString   strSQL,   strName,strPath;  
  CHAR   chValue[255];  
  SDWORD   cbName;  
   
  strSQL   =   "SELECT   next_topo   FROM   line   where   prev_topo   =   '1-6-6-mainline'";  
  rc   =   RunSQL(strSQL);  
  for(rc=FetchData();rc==SQL_SUCCESS;rc=FetchData())  
  {  
  flag   =   true;  
  GetDataOfSQL(1,   SQL_C_CHAR,   chValue,255,&cbName);  
  strName   =   chValue;  
  strPath   =   strPath   +   strName;    
  push(s,strPath,strName);  
  }  
  if(flag)  
  flag   =   false;  
   
  while(!isEmpty(s))  
  {  
  pop(s,strName,strPath);  
  strSQL   =   "SELECT   next_topo   FROM   line   where   prev_topo   =   '"   +   strName   +   "'";  
  rc   =   RunSQL(strSQL);  
  for(rc=FetchData();rc==SQL_SUCCESS;rc=FetchData())  
  {  
  flag   =   true;  
  GetDataOfSQL(1,   SQL_C_CHAR,   chValue,255,&cbName);  
  strName   =   chValue;  
  strPath   =   strPath   +   strName;    
  push(s,strPath,strName);  
  }  
  if(!flag)  
  {  
  AfxMessageBox(strPath);  
  }  
  else  
  flag   =   false;  
  }  
  CloseSQL();  
   
  但一运行就报错,编译能过。我调试,是在调用push时错的,我想应该是CString和堆栈的问题,因为如果我把CString都改为int是可以的。请问如果大家遇到这个问题如何解决。 问题点数:20、回复次数:2Top

1 楼WuOu(天堂*蓝珀湖*仰音*诚彦)回复于 2005-08-08 12:30:19 得分 10

UPTop

2 楼xqk(夏乾坤)回复于 2005-08-08 12:31:42 得分 10

upTop

相关问题

  • 堆 、?栈 、?堆栈
  • ************************************堆,栈,堆栈********************************
  • 堆,栈?
  • 堆栈溢出
  • 堆栈溢出?
  • 堆栈溢出
  • 堆栈问题
  • 老问题:堆、栈、堆栈的区别?
  • ???堆栈溢出???急!
  • vc中的堆栈?

关键词

  • 数据库
  • 线路
  • top
  • 堆栈
  • 终点
  • chvalue
  • topo
  • cstring
  • 起点
  • strpath

得分解答快速导航

  • 帖主:lcrystal623
  • WuOu
  • xqk

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo