|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
就写了这么一点
好多错误,哭了
#include <stdlib.h>
#include <stdio.h>
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
void CreateList_L(LinkList &L,int n){
int i;
L=(LinkList)malloc(sizeof (LNode));
L->next=NULL;
for(i=n;i>0;--i){
p=(LinkList)malloc(sizeof (LNode));
scanf(&p->data);
p->next=L->next;L->next=p;
}
下面是编译时候的报错:
E:\nue\2.cpp(13) : error C2065: 'p' : undeclared identifier
E:\nue\2.cpp(13) : error C2440: '=' : cannot convert from 'struct LNode *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
E:\nue\2.cpp(14) : error C2227: left of '->data' must point to class/struct/union
E:\nue\2.cpp(15) : error C2227: left of '->next' must point to class/struct/union
E:\nue\2.cpp(15) : error C2440: '=' : cannot convert from 'int' to 'struct LNode *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
E:\nue\2.cpp(18) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
- #include <stdio.h>
- #include <stdlib.h>
- typedef int ElemType ;
- typedef struct node {
- ElemType data ;
- struct node * next ;
- } LNode , * LinkList ;
- void CreateList_L(LinkList * L , int n)
- {
- int i ;
- LinkList p , q ;
- for(i = 0 ; i < n ; i ++) {
- if((p = (LinkList)malloc(sizeof (LNode)))) {
- scanf("%d" , & p -> data) ;
- if(! i) {
- p -> next = p ;
- * L = p ;
- } else {
- p -> next = * L ;
- q -> next = p ;
- }
- q = p ;
- } else {
- * L = NULL ;
- fprintf(stderr , "\n\n") ;
- fprintf(stderr , "Error : malloc()\n") ;
- }
- }
- }
复制代码
|
|