关于C语言和数据结构问题

1.
c(5) : error C2143: syntax error : missing ';' before '<class-head>'
c(8) : error C2143: syntax error : missing ':' before 'constant'
c(11) : warning C4028: formal parameter 1 different from declaration
c(11) : warning C4013: 'ptintf' undefined; assuming extern returning int
c(11) : warning C4013: 'exit' undefined; assuming extern returning int
.c(12) : error C2059: syntax error : 'constant'
: error C2037: left of 'list' specifies undefined struct/union 'List'
.c(17) : error C2037: left of 'list' specifies undefined struct/union 'List'
Error executing cl.exe.
以上为c语言检查的错误,想哪位大大能翻译下。
2.编一个用C语言数据结构的程序(vc++6.0环境)
从键盘输入n个整数,产生线性表的顺序存储结构,并输出线性表;
先谢谢大家

1、程序第五行,语法错误,在类的头文件前缺少分号;
程序第八行,语法错误,在常量前缺少分号;
程序第十一行,警告,有一个参数与声明的类型不同;
程序第十一行,警告,ptintf未定义返回值类型,默认为整型;
程序第十一行,警告,exit未定义返回值类型,默认为整型;
程序第十二行,语法错误,常量;
程序第十七行,错误,list左边指定的List为未定义的结构体/共用体;
2、
#include "stdafx.h"
#include "stdio.h"
#include "stdlib.h"

#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define OVERFLOW -2
typedef int Status;
typedef int ElemType;
#define LIST_INIT_SIZE 100
#define LIST_INCREMENT 10
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList ;

void print(ElemType c)
{
printf("%d ",c);
}

void InitList (SqList &L)
{ // 操作结果:构造一个空的顺序线性表L
L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemType));
if(!L.elem)
exit(OVERFLOW); // 存储分配失败
L.length=0; // 空表长度为0
L.listsize=LIST_INIT_SIZE; // 初始存储容量
}

Status ListInsert(SqList &L,int i,ElemType e) //
{ // 初始条件:顺序线性表L已存在,1≤i≤ListLength(L)+1
// 操作结果:在L中第i个位置之前插入新的数据元素e,L的长度加1
ElemType *newbase,*q,*p;
if(i<1||i>L.length+1) // i值不合法
return ERROR;
if(L.length>=L.listsize) // 当前存储空间已满,增加分配
{
if(!(newbase=(ElemType *)realloc(L.elem,(L.listsize+LIST_INCREMENT)*sizeof(ElemType))))
{
printf ("存储分配失败");
exit(OVERFLOW); // 存储分配失败
}
L.elem=newbase; // 新基址
L.listsize+=LIST_INCREMENT; // 增加存储容量
}
q=L.elem+i-1; // q为插入位置
for(p=L.elem+L.length-1;p>=q;--p) // 插入位置及之后的元素右移
*(p+1)=*p;
*q=e; // 插入e
++L.length; // 表长增1
return OK;
}

void ListTraverse(SqList L)
{ // 初始条件:顺序线性表L已存在
// 操作结果:打印输出每一个元素
ElemType *p;
int i;
p=L.elem;
for(i=1;i<=L.length;i++)
{
print(*p++);
printf("\n");
}
}

void main()
{
int i,n;
printf ("请输入一个整数:");
scanf ("%d",&n);
int *temp;
SqList l;
InitList (l);
temp=(int *)malloc ((n+1)*sizeof (int));
if (!temp)
{
printf ("存储分配失败");
exit (OVERFLOW);
}
for (i=0;i<n;i++)
{
printf ("请输入第%d个元素:",i+1);
scanf ("%d",temp);
if (ListInsert(l,i+1,*temp))
temp++;
else
{
printf ("插入失败");
exit(0);
}
}
ListTraverse(l);
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-04-07
程序第五行,语法错误,在类的头文件前缺少分号;
程序第八行,语法错误,在常量前缺少分号;
程序第十一行,警告,有一个参数与声明的类型不同;
程序第十一行,警告,ptintf未定义返回值类型,默认为整型;
程序第十一行,警告,exit未定义返回值类型,默认为整型;
程序第十二行,语法错误,常量;
程序第十七行,错误,list左边指定的List为未定义的结构体/共用体;
第2个回答  2009-04-06
1这个东西不是三言两语说的清的
你上编译错误 可能是你写的程序是 类C语言程序
类C语言程序不考虑 C语言的细节问题 。
也就是说,常用数据结构上的程序是不能直接编译的,要经一系列转化成C或C++ 才能运行。

2

#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
#define overflow -2;
#define OK 1;
typedef int status;
typedef struct {
char *elem;
int length;
int listsize;
}sqlist;
status intlist_sq(sqlist &L){
L.elem =(char *)malloc(LIST_INIT_SIZE*sizeof(char));
if (!L.elem) then exit(overflow);
L.length=0;
L.listsize=LIST_INIT_SIZE;
return OK;
}
////////////////////////////////////////////////////////////
有了以上基本上就可以了
相似回答