首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

新手,关于链表有关问题

2012-04-03 
新手求助,关于链表问题#includestring.h#includectype.h#includemalloc.h#includelimits.h#includ

新手求助,关于链表问题
#include<string.h>
 #include<ctype.h>
 #include<malloc.h> 
 #include<limits.h> 
 #include<stdio.h> 
 #include<stdlib.h> 
 #include<io.h> 
 #include<math.h>
 #include<process.h> 
 #define TRUE 1
 #define FALSE 0
 #define OK 1
 #define ERROR 0
 #define INFEASIBLE -1
 
 typedef int Status; 
 typedef int Boolean; 

 typedef int ElemType;
 #include <stdio.h>
 #include <stdlib.h>
 struct LNode
 {
ElemType data;
LNode *next;
 };
 typedef LNode *LinkList;

 void CreateList_L(LinkList &L,int n){
L=(LinkList)malloc(sizeof(LNode));
L->next=NULL;
for(int i=n;i>0;--i){
   
p=(LinkList)malloc(sizeof(LNode));
scanf(&p->data);
p->next=L->next;L->next=p;
}
 }

 int main()
 {
LinkList L;
CreateList_L(L,2);
m=L->next;
while(m)
{
printf("%d\n",p->data);
p=p->next;
}
 }



VC6.0中报错:--------------------Configuration: 1 - Win32 Debug--------------------
Compiling...
1.cpp
C:\Documents and Settings\Administrator\桌面\1.cpp(34) : error C2065: 'p' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1.cpp(34) : error C2440: '=' : cannot convert from 'struct LNode *' to 'int'
  This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\1.cpp(35) : error C2227: left of '->data' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(36) : error C2227: left of '->next' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(36) : 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
C:\Documents and Settings\Administrator\桌面\1.cpp(44) : error C2065: 'm' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\1.cpp(44) : error C2440: '=' : cannot convert from 'struct LNode *' to 'int'
  This conversion requires a reinterpret_cast, a C-style cast or function-style cast
C:\Documents and Settings\Administrator\桌面\1.cpp(47) : error C2227: left of '->data' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(48) : error C2227: left of '->next' must point to class/struct/union
C:\Documents and Settings\Administrator\桌面\1.cpp(50) : warning C4508: 'main' : function should return a value; 'void' return type assumed
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)


请问怎么解决???

[解决办法]

C/C++ code
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <malloc.h>  #include <limits.h>  #include <stdio.h>  #include <stdlib.h>  #include <io.h>  #include <math.h>#include <process.h> #define TRUE 1#define FALSE 0#define OK 1#define ERROR 0#define INFEASIBLE -1  typedef int Status;  typedef int Boolean;  typedef int ElemType;struct LNode{    ElemType data;    LNode *next;};typedef LNode *LinkList;void CreateList_L(LinkList &L,int n){    LinkList p = NULL;    L = (LinkList)malloc(sizeof(LNode));    L->next = NULL;    for(int i=n;i>0;--i){        p = (LinkList)malloc(sizeof(LNode));        scanf(&p->data);        p->next = L->next;        L->next = p;    }}int main(){    LinkList L = NULL, m = NULL;    CreateList_L( L, 2 );    m = L->next;    while( m != NULL )    {        printf( "%d\n", p->data );        p=p->next;    }    return 0;} 


[解决办法]
(34) : error C2065: 'p' : undeclared identifier
以上错误表示,第34行中p未定义

热点排行