Deleting intermediate files and output files for project 'main2_3 - Win32 Debug'.
--------------------Configuration: main2_3 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
algo2_3_1.cpp
d:\test\cpp\datatype\chapter2\main2_3\algo2_3_1.cpp(248) : fatal error C1010: unexpected end of file while looking for precompiled header directive
main2_3.cpp
Generating Code...
Error executing cl.exe.
main2_3.exe - 1 error(s), 0 warning(s)
检查了一下algo2_3_1.cpp文件结尾没有什么错误,为啥?
12 个解决方案
#1
有几种可能
一是选择了使用预编译头文件,但没在相应的.cpp文件前
#include "stdafx.h"
还有,可能是大括号不匹配。
一是选择了使用预编译头文件,但没在相应的.cpp文件前
#include "stdafx.h"
还有,可能是大括号不匹配。
#2
是不是有些东西没有定义的原因?
#3
有没有在algo2_3_1.cpp文件头#include "stdafx.h"??
#4
#include "stdafx.h"
#5
在main.cpp中已经加入了#include "stdafx.h"了,
晚上回去全部贴出来。
我把 algo2_3_1.cpp 中的内容全部复制到 main.cpp中,执行正常,一点问题都没有。
algo2_3_1.cpp中全部是实现函。
晚上回去全部贴出来。
我把 algo2_3_1.cpp 中的内容全部复制到 main.cpp中,执行正常,一点问题都没有。
algo2_3_1.cpp中全部是实现函。
#6
那你的algo2_3_1.cpp 到底加了#include "stdafx.h"没有 ??
#7
algo2_3_1.cpp 的最上面加#include "stdafx.h"
或者
打开此项目的“属性页”对话框。有关详细信息,请参阅设置 Visual C++ 项目属性。
单击“C/C++”文件夹。
单击“预编译头”属性页。
修改“创建/使用预编译头”属性改为:自动生成 (/YX)。
或者
打开此项目的“属性页”对话框。有关详细信息,请参阅设置 Visual C++ 项目属性。
单击“C/C++”文件夹。
单击“预编译头”属性页。
修改“创建/使用预编译头”属性改为:自动生成 (/YX)。
#8
对不起,各位大哥,周末太郁闷了,没有来。
我创建的时候就自动生成了#include "stdafx.h"在主模块中。
共有以下几个文件:
stdafx.h
algo2_3_1.h
StdAfx.cpp
algo2_3_1.cpp
main2_3.cpp
stdafx.h是系统生成的,内容就不复制了。
algo2_3_1.h中内容如下:
// algo2_1.h : include file for algo 2_3_1 ÏßÐÔ±íµÄÁ´Ê½±íʾºÍʵÏÖ
#if !defined (DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_)
#define DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_
struct LNode
{
ElemType data;
LNode *next;
};
typedef LNode *LinkList;
#endif // !defined(DATATYPE_TEST_20060719_ALGO2_1_INCLUDED_)
main2_3.cpp内容如下:
// main2_3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "..\..\\include\base.h"
typedef int ElemType;
#include "algo2_3_1.h"
//#include "algo2_3_1.cpp"
Status comp(ElemType e1,ElemType e2)
{
if (e1 == e2)
{
return TRUE;
}
else
{
return FALSE;
}
}
void visit(ElemType &e)
{
printf("%d ",e);
}
void dbl(ElemType &e)
{
e *= 2;
}
int main(int argc, char* argv[])
{
LinkList L;
ElemType e,e0;
Status i;
int j,k;
i =InitList(L);
// printf("InitList L.elem =%u L.length=%d L.listsize=%d\n",L.elem,L.length,L.listsize);
for (j=1; j<=5; j++)
{
i= ListInsert(L,1,j);
}
printf("Insert to L's header 1~5 L=");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
i = ClearList(L);
printf("ClearList L");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
for (j=1; j<=10; j++)
{
i= ListInsert(L,j,j);
}
printf("Insert to L's end 1~10 L=");
ListTraverse(L,visit);
printf("\n");
GetElem(L,5,e);
printf("The number five elem is:%d \n",e);
for (j=0; j<=1; j++)
{
k = LocateElem(L,j,comp);
if (k)
{
printf("order: %d elem is square of %d\n",k,j);
}
else
{
printf("not found elem is square, elem: %d\n",j);
}
}
for (j=1; j<=2; j++)
{
GetElem(L,j,e0);
i = PriorElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's prior, elem: %d\n",e0);
}
else
{
printf("elem:%d prior is elem: %d\n",e0,e);
}
}
for (j=ListLength(L)-1; j<=ListLength(L); j++)
{
GetElem(L,j,e0);
i=NextElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's next, elem: %d\n",e0);
}
else
{
printf("elem:%d next is elem: %d\n",e0,e);
}
}
k = ListLength(L);
printf("ListLength L=%d\n",k);
ListTraverse(L,visit);
printf("\n");
for (j=k+1; j>=k; j--)
{
i = ListDelete(L,j,e);
if (i == ERROR)
{
printf("delete L's order number: %d failure!\n",j);
}
else
{
printf("delete OK. elem: %d\n",e);
}
}
printf("printf L's elem:");
ListTraverse(L,visit);
printf("\n");
ListTraverse(L,dbl);
ListTraverse(L,visit);
printf("\n");
DestroyList(L);
printf("after destroy L, L=%u \n",L);
return 0;
}
我创建的时候就自动生成了#include "stdafx.h"在主模块中。
共有以下几个文件:
stdafx.h
algo2_3_1.h
StdAfx.cpp
algo2_3_1.cpp
main2_3.cpp
stdafx.h是系统生成的,内容就不复制了。
algo2_3_1.h中内容如下:
// algo2_1.h : include file for algo 2_3_1 ÏßÐÔ±íµÄÁ´Ê½±íʾºÍʵÏÖ
#if !defined (DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_)
#define DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_
struct LNode
{
ElemType data;
LNode *next;
};
typedef LNode *LinkList;
#endif // !defined(DATATYPE_TEST_20060719_ALGO2_1_INCLUDED_)
main2_3.cpp内容如下:
// main2_3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "..\..\\include\base.h"
typedef int ElemType;
#include "algo2_3_1.h"
//#include "algo2_3_1.cpp"
Status comp(ElemType e1,ElemType e2)
{
if (e1 == e2)
{
return TRUE;
}
else
{
return FALSE;
}
}
void visit(ElemType &e)
{
printf("%d ",e);
}
void dbl(ElemType &e)
{
e *= 2;
}
int main(int argc, char* argv[])
{
LinkList L;
ElemType e,e0;
Status i;
int j,k;
i =InitList(L);
// printf("InitList L.elem =%u L.length=%d L.listsize=%d\n",L.elem,L.length,L.listsize);
for (j=1; j<=5; j++)
{
i= ListInsert(L,1,j);
}
printf("Insert to L's header 1~5 L=");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
i = ClearList(L);
printf("ClearList L");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
for (j=1; j<=10; j++)
{
i= ListInsert(L,j,j);
}
printf("Insert to L's end 1~10 L=");
ListTraverse(L,visit);
printf("\n");
GetElem(L,5,e);
printf("The number five elem is:%d \n",e);
for (j=0; j<=1; j++)
{
k = LocateElem(L,j,comp);
if (k)
{
printf("order: %d elem is square of %d\n",k,j);
}
else
{
printf("not found elem is square, elem: %d\n",j);
}
}
for (j=1; j<=2; j++)
{
GetElem(L,j,e0);
i = PriorElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's prior, elem: %d\n",e0);
}
else
{
printf("elem:%d prior is elem: %d\n",e0,e);
}
}
for (j=ListLength(L)-1; j<=ListLength(L); j++)
{
GetElem(L,j,e0);
i=NextElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's next, elem: %d\n",e0);
}
else
{
printf("elem:%d next is elem: %d\n",e0,e);
}
}
k = ListLength(L);
printf("ListLength L=%d\n",k);
ListTraverse(L,visit);
printf("\n");
for (j=k+1; j>=k; j--)
{
i = ListDelete(L,j,e);
if (i == ERROR)
{
printf("delete L's order number: %d failure!\n",j);
}
else
{
printf("delete OK. elem: %d\n",e);
}
}
printf("printf L's elem:");
ListTraverse(L,visit);
printf("\n");
ListTraverse(L,dbl);
ListTraverse(L,visit);
printf("\n");
DestroyList(L);
printf("after destroy L, L=%u \n",L);
return 0;
}
#9
algo2_3_1.cpp的内容如下:
Status InitList(LinkList &L)
{
L = (LinkList)malloc(sizeof(LNode));
if (!L)
{
exit(OVERFLOW);
}
L->next = NULL;
return OK;
}
Status DestroyList(LinkList &L)
{
if (!L)
{
exit(OVERFLOW);
}
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
free(L);
L = NULL;
return OK;
}
Status ClearList(LinkList L)
{
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
L->next = NULL;
return OK;
}
Status ListEmpty(LinkList L)
{
if (!L->next)
{
return TRUE;
}
else
{
return FALSE;
}
}
// 2006.08.08 22:08 ÖÁ´ËÐÐ
int ListLength(LinkList L)
{
int i=0;
LinkList p = L->next;
while (p)
{
i++;
p = p->next;
}
return i;
}
Status GetElem(LinkList L,int i,ElemType &e)
{
int j=1;
LinkList p = L->next;
while (p && j<i)
{
p = p->next;
j++;
}
if (!p || j>i)
{
return ERROR;
}
e = p->data;
return OK;
}
int LocateElem(LinkList L,ElemType e,Status(*compare)(ElemType,ElemType))
{
int i = 0;
Status flag = FALSE;
LinkList p = L->next;
while (p)
{
i++;
if (compare(p->data,e))
{
flag = TRUE;
break;
}
p = p->next;
}
if (flag)
{
return i;
}
else
{
return ERROR;
}
}
Status PriorElem(LinkList L,ElemType cur_e,ElemType &pre_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (q->data == cur_e)
{
pre_e = p->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status NextElem(LinkList L,ElemType cur_e,ElemType &next_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (p->data == cur_e)
{
next_e = q->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status ListInsert(LinkList L,int i,ElemType e)
{
int j = 0;
LinkList s,p = L;
while (p && j<i-1)
{
p = p->next;
j++;
}
if (!p || j>i-1)
{
return ERROR;
}
s = (LinkList)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
Status ListDelete(LinkList L,int i,ElemType &e)
{
int j = 0;
LinkList q,p = L;
while (p->next && j<i-1)
{
p = p->next;
j++;
}
if (!p->next || j>i-1)
{
return ERROR;
}
q = p->next;
p->next = q->next;
e = q->data;
free(q);
return OK;
}
Status ListTraverse(LinkList L,void(*vi)(ElemType &))
{
LinkList p = L->next;
while (p)
{
vi(p->data);
p = p->next;
}
//printf("\n");
return OK;
}
还有上面一段main2_3_1.cpp中:
//#include "algo2_3_1.cpp"是没有加注释的,因为不能编译我把algo2_3_1.cpp中的全部内容移到main2_3_1.cpp中,全部正常。
base.h只是一些数据的定义。
Status InitList(LinkList &L)
{
L = (LinkList)malloc(sizeof(LNode));
if (!L)
{
exit(OVERFLOW);
}
L->next = NULL;
return OK;
}
Status DestroyList(LinkList &L)
{
if (!L)
{
exit(OVERFLOW);
}
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
free(L);
L = NULL;
return OK;
}
Status ClearList(LinkList L)
{
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
L->next = NULL;
return OK;
}
Status ListEmpty(LinkList L)
{
if (!L->next)
{
return TRUE;
}
else
{
return FALSE;
}
}
// 2006.08.08 22:08 ÖÁ´ËÐÐ
int ListLength(LinkList L)
{
int i=0;
LinkList p = L->next;
while (p)
{
i++;
p = p->next;
}
return i;
}
Status GetElem(LinkList L,int i,ElemType &e)
{
int j=1;
LinkList p = L->next;
while (p && j<i)
{
p = p->next;
j++;
}
if (!p || j>i)
{
return ERROR;
}
e = p->data;
return OK;
}
int LocateElem(LinkList L,ElemType e,Status(*compare)(ElemType,ElemType))
{
int i = 0;
Status flag = FALSE;
LinkList p = L->next;
while (p)
{
i++;
if (compare(p->data,e))
{
flag = TRUE;
break;
}
p = p->next;
}
if (flag)
{
return i;
}
else
{
return ERROR;
}
}
Status PriorElem(LinkList L,ElemType cur_e,ElemType &pre_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (q->data == cur_e)
{
pre_e = p->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status NextElem(LinkList L,ElemType cur_e,ElemType &next_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (p->data == cur_e)
{
next_e = q->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status ListInsert(LinkList L,int i,ElemType e)
{
int j = 0;
LinkList s,p = L;
while (p && j<i-1)
{
p = p->next;
j++;
}
if (!p || j>i-1)
{
return ERROR;
}
s = (LinkList)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
Status ListDelete(LinkList L,int i,ElemType &e)
{
int j = 0;
LinkList q,p = L;
while (p->next && j<i-1)
{
p = p->next;
j++;
}
if (!p->next || j>i-1)
{
return ERROR;
}
q = p->next;
p->next = q->next;
e = q->data;
free(q);
return OK;
}
Status ListTraverse(LinkList L,void(*vi)(ElemType &))
{
LinkList p = L->next;
while (p)
{
vi(p->data);
p = p->next;
}
//printf("\n");
return OK;
}
还有上面一段main2_3_1.cpp中:
//#include "algo2_3_1.cpp"是没有加注释的,因为不能编译我把algo2_3_1.cpp中的全部内容移到main2_3_1.cpp中,全部正常。
base.h只是一些数据的定义。
#10
那你的algo2_3_1.cpp 到底加了#include "stdafx.h"没有 ??
加一下
加一下
#11
加了以后错误更多了:
Deleting intermediate files and output files for project 'main2_3 - Win32 Debug'.
--------------------Configuration: main2_3 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
algo2_3_1.cpp
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2146: syntax error : missing ';' before identifier 'InitList'
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2501: 'Status' : missing storage-class or type specifiers
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : fatal error C1004: unexpected end of file found
main2_3.cpp
Generating Code...
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\algo2_3_1.sbr': No such file or directory
Error executing bscmake.exe.
main2_3.exe - 4 error(s), 0 warning(s)
Deleting intermediate files and output files for project 'main2_3 - Win32 Debug'.
--------------------Configuration: main2_3 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
algo2_3_1.cpp
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2146: syntax error : missing ';' before identifier 'InitList'
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2501: 'Status' : missing storage-class or type specifiers
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : fatal error C1004: unexpected end of file found
main2_3.cpp
Generating Code...
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\algo2_3_1.sbr': No such file or directory
Error executing bscmake.exe.
main2_3.exe - 4 error(s), 0 warning(s)
#12
感谢 seu07201213(【东南】〖汪洋中的一片叶子〗) 已经帮助编译本程序。
#1
有几种可能
一是选择了使用预编译头文件,但没在相应的.cpp文件前
#include "stdafx.h"
还有,可能是大括号不匹配。
一是选择了使用预编译头文件,但没在相应的.cpp文件前
#include "stdafx.h"
还有,可能是大括号不匹配。
#2
是不是有些东西没有定义的原因?
#3
有没有在algo2_3_1.cpp文件头#include "stdafx.h"??
#4
#include "stdafx.h"
#5
在main.cpp中已经加入了#include "stdafx.h"了,
晚上回去全部贴出来。
我把 algo2_3_1.cpp 中的内容全部复制到 main.cpp中,执行正常,一点问题都没有。
algo2_3_1.cpp中全部是实现函。
晚上回去全部贴出来。
我把 algo2_3_1.cpp 中的内容全部复制到 main.cpp中,执行正常,一点问题都没有。
algo2_3_1.cpp中全部是实现函。
#6
那你的algo2_3_1.cpp 到底加了#include "stdafx.h"没有 ??
#7
algo2_3_1.cpp 的最上面加#include "stdafx.h"
或者
打开此项目的“属性页”对话框。有关详细信息,请参阅设置 Visual C++ 项目属性。
单击“C/C++”文件夹。
单击“预编译头”属性页。
修改“创建/使用预编译头”属性改为:自动生成 (/YX)。
或者
打开此项目的“属性页”对话框。有关详细信息,请参阅设置 Visual C++ 项目属性。
单击“C/C++”文件夹。
单击“预编译头”属性页。
修改“创建/使用预编译头”属性改为:自动生成 (/YX)。
#8
对不起,各位大哥,周末太郁闷了,没有来。
我创建的时候就自动生成了#include "stdafx.h"在主模块中。
共有以下几个文件:
stdafx.h
algo2_3_1.h
StdAfx.cpp
algo2_3_1.cpp
main2_3.cpp
stdafx.h是系统生成的,内容就不复制了。
algo2_3_1.h中内容如下:
// algo2_1.h : include file for algo 2_3_1 ÏßÐÔ±íµÄÁ´Ê½±íʾºÍʵÏÖ
#if !defined (DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_)
#define DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_
struct LNode
{
ElemType data;
LNode *next;
};
typedef LNode *LinkList;
#endif // !defined(DATATYPE_TEST_20060719_ALGO2_1_INCLUDED_)
main2_3.cpp内容如下:
// main2_3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "..\..\\include\base.h"
typedef int ElemType;
#include "algo2_3_1.h"
//#include "algo2_3_1.cpp"
Status comp(ElemType e1,ElemType e2)
{
if (e1 == e2)
{
return TRUE;
}
else
{
return FALSE;
}
}
void visit(ElemType &e)
{
printf("%d ",e);
}
void dbl(ElemType &e)
{
e *= 2;
}
int main(int argc, char* argv[])
{
LinkList L;
ElemType e,e0;
Status i;
int j,k;
i =InitList(L);
// printf("InitList L.elem =%u L.length=%d L.listsize=%d\n",L.elem,L.length,L.listsize);
for (j=1; j<=5; j++)
{
i= ListInsert(L,1,j);
}
printf("Insert to L's header 1~5 L=");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
i = ClearList(L);
printf("ClearList L");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
for (j=1; j<=10; j++)
{
i= ListInsert(L,j,j);
}
printf("Insert to L's end 1~10 L=");
ListTraverse(L,visit);
printf("\n");
GetElem(L,5,e);
printf("The number five elem is:%d \n",e);
for (j=0; j<=1; j++)
{
k = LocateElem(L,j,comp);
if (k)
{
printf("order: %d elem is square of %d\n",k,j);
}
else
{
printf("not found elem is square, elem: %d\n",j);
}
}
for (j=1; j<=2; j++)
{
GetElem(L,j,e0);
i = PriorElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's prior, elem: %d\n",e0);
}
else
{
printf("elem:%d prior is elem: %d\n",e0,e);
}
}
for (j=ListLength(L)-1; j<=ListLength(L); j++)
{
GetElem(L,j,e0);
i=NextElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's next, elem: %d\n",e0);
}
else
{
printf("elem:%d next is elem: %d\n",e0,e);
}
}
k = ListLength(L);
printf("ListLength L=%d\n",k);
ListTraverse(L,visit);
printf("\n");
for (j=k+1; j>=k; j--)
{
i = ListDelete(L,j,e);
if (i == ERROR)
{
printf("delete L's order number: %d failure!\n",j);
}
else
{
printf("delete OK. elem: %d\n",e);
}
}
printf("printf L's elem:");
ListTraverse(L,visit);
printf("\n");
ListTraverse(L,dbl);
ListTraverse(L,visit);
printf("\n");
DestroyList(L);
printf("after destroy L, L=%u \n",L);
return 0;
}
我创建的时候就自动生成了#include "stdafx.h"在主模块中。
共有以下几个文件:
stdafx.h
algo2_3_1.h
StdAfx.cpp
algo2_3_1.cpp
main2_3.cpp
stdafx.h是系统生成的,内容就不复制了。
algo2_3_1.h中内容如下:
// algo2_1.h : include file for algo 2_3_1 ÏßÐÔ±íµÄÁ´Ê½±íʾºÍʵÏÖ
#if !defined (DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_)
#define DATATYPE_TEST_20060719_ALGO2_3_1_INCLUDED_
struct LNode
{
ElemType data;
LNode *next;
};
typedef LNode *LinkList;
#endif // !defined(DATATYPE_TEST_20060719_ALGO2_1_INCLUDED_)
main2_3.cpp内容如下:
// main2_3.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "..\..\\include\base.h"
typedef int ElemType;
#include "algo2_3_1.h"
//#include "algo2_3_1.cpp"
Status comp(ElemType e1,ElemType e2)
{
if (e1 == e2)
{
return TRUE;
}
else
{
return FALSE;
}
}
void visit(ElemType &e)
{
printf("%d ",e);
}
void dbl(ElemType &e)
{
e *= 2;
}
int main(int argc, char* argv[])
{
LinkList L;
ElemType e,e0;
Status i;
int j,k;
i =InitList(L);
// printf("InitList L.elem =%u L.length=%d L.listsize=%d\n",L.elem,L.length,L.listsize);
for (j=1; j<=5; j++)
{
i= ListInsert(L,1,j);
}
printf("Insert to L's header 1~5 L=");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
i = ClearList(L);
printf("ClearList L");
ListTraverse(L,visit);
printf("\n");
i = ListEmpty(L);
printf("L is empty: %d (1:yes 0:no)\n",i);
for (j=1; j<=10; j++)
{
i= ListInsert(L,j,j);
}
printf("Insert to L's end 1~10 L=");
ListTraverse(L,visit);
printf("\n");
GetElem(L,5,e);
printf("The number five elem is:%d \n",e);
for (j=0; j<=1; j++)
{
k = LocateElem(L,j,comp);
if (k)
{
printf("order: %d elem is square of %d\n",k,j);
}
else
{
printf("not found elem is square, elem: %d\n",j);
}
}
for (j=1; j<=2; j++)
{
GetElem(L,j,e0);
i = PriorElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's prior, elem: %d\n",e0);
}
else
{
printf("elem:%d prior is elem: %d\n",e0,e);
}
}
for (j=ListLength(L)-1; j<=ListLength(L); j++)
{
GetElem(L,j,e0);
i=NextElem(L,e0,e);
if (i == INFEASIBLE)
{
printf("not found elem's next, elem: %d\n",e0);
}
else
{
printf("elem:%d next is elem: %d\n",e0,e);
}
}
k = ListLength(L);
printf("ListLength L=%d\n",k);
ListTraverse(L,visit);
printf("\n");
for (j=k+1; j>=k; j--)
{
i = ListDelete(L,j,e);
if (i == ERROR)
{
printf("delete L's order number: %d failure!\n",j);
}
else
{
printf("delete OK. elem: %d\n",e);
}
}
printf("printf L's elem:");
ListTraverse(L,visit);
printf("\n");
ListTraverse(L,dbl);
ListTraverse(L,visit);
printf("\n");
DestroyList(L);
printf("after destroy L, L=%u \n",L);
return 0;
}
#9
algo2_3_1.cpp的内容如下:
Status InitList(LinkList &L)
{
L = (LinkList)malloc(sizeof(LNode));
if (!L)
{
exit(OVERFLOW);
}
L->next = NULL;
return OK;
}
Status DestroyList(LinkList &L)
{
if (!L)
{
exit(OVERFLOW);
}
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
free(L);
L = NULL;
return OK;
}
Status ClearList(LinkList L)
{
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
L->next = NULL;
return OK;
}
Status ListEmpty(LinkList L)
{
if (!L->next)
{
return TRUE;
}
else
{
return FALSE;
}
}
// 2006.08.08 22:08 ÖÁ´ËÐÐ
int ListLength(LinkList L)
{
int i=0;
LinkList p = L->next;
while (p)
{
i++;
p = p->next;
}
return i;
}
Status GetElem(LinkList L,int i,ElemType &e)
{
int j=1;
LinkList p = L->next;
while (p && j<i)
{
p = p->next;
j++;
}
if (!p || j>i)
{
return ERROR;
}
e = p->data;
return OK;
}
int LocateElem(LinkList L,ElemType e,Status(*compare)(ElemType,ElemType))
{
int i = 0;
Status flag = FALSE;
LinkList p = L->next;
while (p)
{
i++;
if (compare(p->data,e))
{
flag = TRUE;
break;
}
p = p->next;
}
if (flag)
{
return i;
}
else
{
return ERROR;
}
}
Status PriorElem(LinkList L,ElemType cur_e,ElemType &pre_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (q->data == cur_e)
{
pre_e = p->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status NextElem(LinkList L,ElemType cur_e,ElemType &next_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (p->data == cur_e)
{
next_e = q->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status ListInsert(LinkList L,int i,ElemType e)
{
int j = 0;
LinkList s,p = L;
while (p && j<i-1)
{
p = p->next;
j++;
}
if (!p || j>i-1)
{
return ERROR;
}
s = (LinkList)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
Status ListDelete(LinkList L,int i,ElemType &e)
{
int j = 0;
LinkList q,p = L;
while (p->next && j<i-1)
{
p = p->next;
j++;
}
if (!p->next || j>i-1)
{
return ERROR;
}
q = p->next;
p->next = q->next;
e = q->data;
free(q);
return OK;
}
Status ListTraverse(LinkList L,void(*vi)(ElemType &))
{
LinkList p = L->next;
while (p)
{
vi(p->data);
p = p->next;
}
//printf("\n");
return OK;
}
还有上面一段main2_3_1.cpp中:
//#include "algo2_3_1.cpp"是没有加注释的,因为不能编译我把algo2_3_1.cpp中的全部内容移到main2_3_1.cpp中,全部正常。
base.h只是一些数据的定义。
Status InitList(LinkList &L)
{
L = (LinkList)malloc(sizeof(LNode));
if (!L)
{
exit(OVERFLOW);
}
L->next = NULL;
return OK;
}
Status DestroyList(LinkList &L)
{
if (!L)
{
exit(OVERFLOW);
}
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
free(L);
L = NULL;
return OK;
}
Status ClearList(LinkList L)
{
LinkList p,q;
p = L->next;
while(p)
{
q=p->next;
free(p);
p=q;
}
L->next = NULL;
return OK;
}
Status ListEmpty(LinkList L)
{
if (!L->next)
{
return TRUE;
}
else
{
return FALSE;
}
}
// 2006.08.08 22:08 ÖÁ´ËÐÐ
int ListLength(LinkList L)
{
int i=0;
LinkList p = L->next;
while (p)
{
i++;
p = p->next;
}
return i;
}
Status GetElem(LinkList L,int i,ElemType &e)
{
int j=1;
LinkList p = L->next;
while (p && j<i)
{
p = p->next;
j++;
}
if (!p || j>i)
{
return ERROR;
}
e = p->data;
return OK;
}
int LocateElem(LinkList L,ElemType e,Status(*compare)(ElemType,ElemType))
{
int i = 0;
Status flag = FALSE;
LinkList p = L->next;
while (p)
{
i++;
if (compare(p->data,e))
{
flag = TRUE;
break;
}
p = p->next;
}
if (flag)
{
return i;
}
else
{
return ERROR;
}
}
Status PriorElem(LinkList L,ElemType cur_e,ElemType &pre_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (q->data == cur_e)
{
pre_e = p->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status NextElem(LinkList L,ElemType cur_e,ElemType &next_e)
{
LinkList q,p = L->next;
Status flag = INFEASIBLE;
if (!p)
{
return flag;
}
q = p->next;
while (q)
{
if (p->data == cur_e)
{
next_e = q->data;
flag = TRUE;
break;
}
p = q;
q = q->next;
}
return flag;
}
Status ListInsert(LinkList L,int i,ElemType e)
{
int j = 0;
LinkList s,p = L;
while (p && j<i-1)
{
p = p->next;
j++;
}
if (!p || j>i-1)
{
return ERROR;
}
s = (LinkList)malloc(sizeof(LNode));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
Status ListDelete(LinkList L,int i,ElemType &e)
{
int j = 0;
LinkList q,p = L;
while (p->next && j<i-1)
{
p = p->next;
j++;
}
if (!p->next || j>i-1)
{
return ERROR;
}
q = p->next;
p->next = q->next;
e = q->data;
free(q);
return OK;
}
Status ListTraverse(LinkList L,void(*vi)(ElemType &))
{
LinkList p = L->next;
while (p)
{
vi(p->data);
p = p->next;
}
//printf("\n");
return OK;
}
还有上面一段main2_3_1.cpp中:
//#include "algo2_3_1.cpp"是没有加注释的,因为不能编译我把algo2_3_1.cpp中的全部内容移到main2_3_1.cpp中,全部正常。
base.h只是一些数据的定义。
#10
那你的algo2_3_1.cpp 到底加了#include "stdafx.h"没有 ??
加一下
加一下
#11
加了以后错误更多了:
Deleting intermediate files and output files for project 'main2_3 - Win32 Debug'.
--------------------Configuration: main2_3 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
algo2_3_1.cpp
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2146: syntax error : missing ';' before identifier 'InitList'
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2501: 'Status' : missing storage-class or type specifiers
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : fatal error C1004: unexpected end of file found
main2_3.cpp
Generating Code...
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\algo2_3_1.sbr': No such file or directory
Error executing bscmake.exe.
main2_3.exe - 4 error(s), 0 warning(s)
Deleting intermediate files and output files for project 'main2_3 - Win32 Debug'.
--------------------Configuration: main2_3 - Win32 Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
algo2_3_1.cpp
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2146: syntax error : missing ';' before identifier 'InitList'
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : error C2501: 'Status' : missing storage-class or type specifiers
D:\test\Cpp\DataType\chapter2\main2_3\algo2_3_1.cpp(5) : fatal error C1004: unexpected end of file found
main2_3.cpp
Generating Code...
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\algo2_3_1.sbr': No such file or directory
Error executing bscmake.exe.
main2_3.exe - 4 error(s), 0 warning(s)
#12
感谢 seu07201213(【东南】〖汪洋中的一片叶子〗) 已经帮助编译本程序。