找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 1608|回复: 9

求这个程序的错误

[复制链接]
发表于 2009-10-31 01:13:26 | 显示全部楼层 |阅读模式 IP:江苏扬州
#include<iostrenm> #define LIST_INIT_SIZE 100 //初始分配量 #define LISTINCREMENT 10 //分配增量 using namespace std; typedef struct{ int *elem; //存储空间基址 int length; //当前长度 int listsize; //当前分配的存储容量以sizeof(int)为单位 } int CreatList_Sq(SqList &L){ //构造一个顺序表 L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int)); if(!L.elem) exit(OVERFLOW); //分配失败 L.length=0; //空表长度为0 L.listsize=LIST_INIT_SIZE; //初始存储容量 for(i=0;i<LIST_INIT_SIZE;i++){ L.elem[i]=i; L.length++; }//Creatlist_Sq return OK; } int ListDelete_Sq(SqList &L,int i,int &e){ //在顺序线性表L中删除第i个元素,并用e返回其值 //i合法值为1<=i<=ListLength_Sq(L) int i,*p,*q; if((i<1)||(i>L.length)) return ERROR; //i值不合法 p=&(L.elem[i-1]); //p为被删除的元素的位置 e=*p; //被删除的元素的值赋给e q=L.elem+(L.length-1)*2; //表尾元素的位置 for(++p;p<=q;++p) *(p-1)=*p; --L.length; //表长减1 return OK; }//ListDelete_Sq int main(){ int deleted_location,deleted_element; cout<<"请输入你所要删除的元素位置:"; cin>>deleted_location; CreatList_Sq(SqList List); ListDelete_Sq(SqList List,int deleted_location,int deleted_element); cout>>"被删除的元素是:"; >>deleted_element; }
经过编译后出现了这样一个问题:
c:\documents and settings\tony\桌面\新建文件夹\c++.cpp(1) : fatal error C1083: Cannot open include file: 'iostrenm': No such file or directory Error executing cl.exe.
怎样除错呢???(我的是VC++6.0,创天中文版,还是盗版的)
要使用malloc函数,在C++里需要什么什么样的库函数呢???
关于main()函数的编写,在C++里,main()函数是有类型的,怎样确定是void型还是int型的呢???我的main()函数编写的正确吗???
请赐教,谢谢!
发表于 2009-10-31 01:13:27 | 显示全部楼层 IP:江苏扬州
晕死!!!
是你自己写错了!! iostream _->iostrenm 当然打不开罗!!
————————————————
尽善尽美!!
回复

使用道具 举报

发表于 2009-10-31 01:13:28 | 显示全部楼层 IP:江苏扬州
我的天,按照corrupt兄的指点,我又重新编译啦。
结果15 error(s), 1 warning(s)。天呀!
回复

使用道具 举报

发表于 2009-10-31 01:13:28 | 显示全部楼层 IP:江苏扬州
main()函数的返回值会返回去哪里呢???
刚学《数据结构》,老师叫用VC++上机,好不适应呀!
回复

使用道具 举报

发表于 2009-10-31 01:13:29 | 显示全部楼层 IP:江苏扬州
我看了半天 怎么没见 main 函数啊?
是不是抄书的啊??
回复

使用道具 举报

发表于 2009-10-31 01:13:30 | 显示全部楼层 IP:江苏扬州
我晕,main()函数不是在最后面吗???
回复

使用道具 举报

发表于 2009-10-31 01:13:31 | 显示全部楼层 IP:江苏扬州
#include<iostream> using namespace std;
#define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define OVERFLOW -1 #define OK 1 #define ERROR -1
struct SqList { int *elem; int length; int listsize; };
int CreatList_Sq(SqList &L) { int i; L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int)); if(!L.elem) exit(OVERFLOW); L.length=0; L.listsize=LIST_INIT_SIZE; for(i=0;i<LIST_INIT_SIZE;i++) { L.elem[i]=i; L.length++; }//Creatlist_Sq return OK; }
int ListDelete_Sq(SqList &L,int i,int &e) { int *p,*q; if((i<1)||(i>L.length)) return ERROR; p=&(L.elem[i-1]); e=*p; q=L.elem+(L.length-1); for(++p;p<=q;++p)     // 这个算法只是将后面的往前移,但最后一个元素没有清除掉,所以算法不对! *(p-1)=*p; --L.length; return OK; }//ListDelete_Sq
void ListDelete(SqList &L) { if(L.elem) free(L.elem); }
int main() { int deleted_location,deleted_element; cout<<"请输入你所要删除的元素位置:"; cin>>deleted_location; SqList List; CreatList_Sq(List); ListDelete_Sq(List,deleted_location,deleted_element); cout<<"被删除的元素是:"<<deleted_element; ListDelete(List); //动态开辟的内存需要清除掉.
return 0; }
回复

使用道具 举报

发表于 2009-10-31 01:13:32 | 显示全部楼层 IP:江苏扬州
书上的有的只是片断。都不是完整的程序~~呵呵~~我也是刚学的~~项目需要,呵呵~~大家多多帮忙!
回复

使用道具 举报

发表于 2009-10-31 01:13:38 | 显示全部楼层 IP:江苏扬州
自己对kai修改过程序的改进之处如下:
增加:1。#include<malloc.h> 因为在程序中使用了malloc();和free();。
2。free(q); 程序中q被用来指向最后一个元素。
#include<malloc.h> #include<iostream> using namespace std;
#define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define OVERFLOW -1 #define OK 1 #define ERROR -1
struct SqList{ int *elem; int length; int listsize; };
int CreatList_Sq(SqList &L){ int i; L.elem=(int *)malloc(LIST_INIT_SIZE*sizeof(int)); if(!L.elem) exit(OVERFLOW); L.length=0; L.listsize=LIST_INIT_SIZE; for(i=0;i<LIST_INIT_SIZE;i++){ L.elem[i]=i; L.length++; } return OK; }//CreateList_Sq
int ListDelete_Sq(SqList &L,int i,int &e){ int *p,*q; if((i<1)||(i>L.length)) return ERROR; p=&(L.elem[i-1]); e=*p; q=L.elem+(L.length-1); for(++p;p<=q;++p)      *(p-1)=*p; free(q); --L.length; return OK; }//ListDelete_Sq
void ListDelete(SqList &L){ if(L.elem) free(L.elem); }
int main(){ int deleted_location,deleted_element; cout<<"请输入你所要删除的元素位置:"; cin>>deleted_location; SqList List; CreatList_Sq(List); ListDelete_Sq(List,deleted_location,deleted_element); cout<<"被删除的元素是:"<<deleted_element; ListDelete(List); //动态开辟的内存需要清除掉. return 0; }
但是还是有10个错误
回复

使用道具 举报

发表于 2009-10-31 01:13:39 | 显示全部楼层 IP:江苏扬州
你在void ListDelete(SqList &L)函数里面free(L.elem); 清空了L.elem,传址传进来的空地址p=&(L.elem[i-1]);
for(++p;p<=q;++p) *(p-1)=*p; //两个空地址在瞎掰……
你漏了#include<stdlib.h>,exit(int paramter)函数需要这个头文件支持。另,不要按书上的变量名,长得可以,我看得头晕,变量名要有自己的特色,书上只是为了让你看得懂,而不是看得有效率。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 15:20 , Processed in 0.205193 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表